0
到目前爲止,我有一個android應用程序,它可以將數據(簡單文本)保存到sqlite數據庫並顯示到列表視圖中。我希望能夠添加圖像,但我不知道如何。如何將圖像添加到sqlite ListView?
這裏是它創建的行類的,每次我添加一些文字:
公共類TestDatabaseActivity擴展ListActivity { 私人CommentsDataSource數據源;
int holanumero;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_database);
datasource = new CommentsDataSource(this);
datasource.open();
List<Comment> values = datasource.getAllComments();
// use the SimpleCursorAdapter to show the
// elements in a ListView
ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
final ListView listadeutiles = (ListView) findViewById(android.R.id.list);
//
listadeutiles.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
holanumero = position;
}});
}
// Will be called via the onClick attribute
// of the buttons in main.xml
public void onClick(View view) {
@SuppressWarnings("unchecked")
ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter();
Comment comment = null;
switch (view.getId())
{
case R.id.add:
EditText texto1 = (EditText) findViewById(R.id.editText1);
String palabra1 = texto1.getText().toString();
EditText texto2 = (EditText) findViewById(R.id.editText2);
String palabra2 = texto2.getText().toString();
String palabra3 = palabra1 + palabra2;
comment = datasource.createComment(palabra3);
adapter.add(comment);
texto1.setText("");
texto2.setText("");
break;
case R.id.delete:
if (getListAdapter().getCount() > 0) {
comment = (Comment) getListAdapter().getItem(holanumero);
datasource.deleteComment(comment);
adapter.remove(comment);
}
break;
}
adapter.notifyDataSetChanged();
}
@Override
protected void onResume() {
datasource.open();
super.onResume();
}
@Override
protected void onPause() {
datasource.close();
super.onPause();
}
使用blob保存圖像到sqlite,但我建議你不要將圖像保存到sqlite中,將它們保存在SD卡中的某個地方並從那裏使用。 – Deepak