BLOBを含むSQLiteのリストビュー、ベースアダプタ、データがあります。 SQLクエリが変更された場合はどうなりますか? (ボタンを押して新しいSQLクエリを実行した後)adapter.notifyDataSetChangedを使用する必要がありますどこに配置するadapter.notifyDataSetChanged
このコード行はどこに置くことができますか?
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.example);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
placeData = new DatabaseSQL(this);
String cmd = "select * from plaatjes ";
Cursor cursors = getRawEvents(cmd);
if (cursors.moveToNext()) {
getDataAndPopulate(cmd);
}
}
private void getDataAndPopulate(String cmd) {
id = new ArrayList<String>();
image = new ArrayList<byte[]>();
caption = new ArrayList<String>();
description = new ArrayList<String>();
Cursor cursor = getRawEvents(cmd);
while (cursor.moveToNext()) {
String temp_id = cursor.getString(0);
byte[] temp_image = cursor.getBlob(1);
String temp_caption = cursor.getString(2);
String temp_description = cursor.getString(3);
id.add(temp_id);
image.add(temp_image);
caption.add(temp_caption);
description.add(temp_description);
}
String[] captionArray = (String[]) caption.toArray(
new String[caption.size()]);
ItemsAdapter itemsAdapter = new ItemsAdapter(
Example.this, R.layout.item,
captionArray);
setListAdapter(itemsAdapter);
}
private class ItemsAdapter extends BaseAdapter {
String[] items;
public ItemsAdapter(Context context, int textViewResourceId,
String[] items) {
this.items = items;
}
@Override
public View getView(final int POSITION, View convertView,
ViewGroup parent) {
TextView desc;
TextView cap;
View view = convertView;
ImageView img;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.item, null);
}
img = (ImageView) view.findViewById(R.id.image);
cap = (TextView) view.findViewById(R.id.caption);
desc = (TextView) view.findViewById(R.id.description);
cap.setText(caption.get(POSITION));
desc.setText(description.get(POSITION));
img.setImageBitmap(BitmapFactory.decodeByteArray(image.get(POSITION), 0, image.get(POSITION).length));
return view;
}
public int getCount() {
return items.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
}
private Cursor getRawEvents(String sql) {
SQLiteDatabase db = (placeData).getReadableDatabase();
Cursor cursor = db.rawQuery(sql, null);
startManagingCursor(cursor);
return cursor;
}
private Cursor getEvents(String table) {
SQLiteDatabase db = (placeData).getReadableDatabase();
Cursor cursor = db.query(table, null, null, null, null, null, null);
startManagingCursor(cursor);
return cursor;
}
}
それはitemsAdapterまだ知らないその時点であなたのgetDataAndPopulate(文字列CMD)法 – waqaslam
でそれを使用しています。私はsetListAdapter(itemsAdapter)とその下の1行の上に1行だけ試してみましたが、動作しません。 –
の最初の行には、ボタンの* onClickListener *イベント – user1273768