Hello,
I need your help.
I am making gallery view, and I have to set adapter for that gallery.
I have cursor as private element of adapter, and it works.
But when I need to delete some element from gallery, I call method NotifyDataSetChanged(), but I can't override that method ( or I don't know ).
So how to delete item from gallery when I click on some item.
Or is there better way to do this, like to every time where I have to return Object I search in database, but I don't know how to search in database for Nth element.
Here is my code for adapter which extends BaseAdapter:
[pre]
private class myGalleryAdapter extends BaseAdapter {
private int mGalleryItemBackground;
private Context mContext;
private Cursor cursor;
public myGalleryAdapter( Context context ) {
mContext = context;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
String[] columns = { Classroom.ID, Classroom.TITLE, Classroom.DESCRIPTION };
cursor = database.GetAllClassroom(columns);
}
@Override
public int getCount() {
return cursor.getCount();
//return (int)database.NumberOfRows();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
cursor.moveToPosition(position);
return cursor.getLong(0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(mContext);
cursor.moveToPosition(position);
tv.setText( cursor.getString(1) );
tv.setLayoutParams(new Gallery.LayoutParams(150, 100));
tv.setBackgroundResource(mGalleryItemBackground);
return tv;
}
}
[/pre]
I need your help.
I am making gallery view, and I have to set adapter for that gallery.
I have cursor as private element of adapter, and it works.
But when I need to delete some element from gallery, I call method NotifyDataSetChanged(), but I can't override that method ( or I don't know ).
So how to delete item from gallery when I click on some item.
Or is there better way to do this, like to every time where I have to return Object I search in database, but I don't know how to search in database for Nth element.
Here is my code for adapter which extends BaseAdapter:
[pre]
private class myGalleryAdapter extends BaseAdapter {
private int mGalleryItemBackground;
private Context mContext;
private Cursor cursor;
public myGalleryAdapter( Context context ) {
mContext = context;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = a.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
String[] columns = { Classroom.ID, Classroom.TITLE, Classroom.DESCRIPTION };
cursor = database.GetAllClassroom(columns);
}
@Override
public int getCount() {
return cursor.getCount();
//return (int)database.NumberOfRows();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
cursor.moveToPosition(position);
return cursor.getLong(0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(mContext);
cursor.moveToPosition(position);
tv.setText( cursor.getString(1) );
tv.setLayoutParams(new Gallery.LayoutParams(150, 100));
tv.setBackgroundResource(mGalleryItemBackground);
return tv;
}
}
[/pre]