我有使用从数据库中检索的数组适配器的文本列表视图。它工作正常。但是我将图像路径存储在数据库中,我希望它使用光标显示在带有图像和文本视图的自定义列表中。任何人都建议我举个例子
public class SingleItem extends Activity {
DatabaseHelper db;
Cursor c;
private CustomAdapter Adapter;
protected Object mActionMode;
String[] Phno,Description;
int[] Amount;
int j=0,pos;
private ArrayList<String> arrayList = new ArrayList<String>();
private SQLiteDatabase expenses;
ListView detail;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.singleitem);
TextView item=(TextView) findViewById(R.id.textView1);
detail=(ListView) findViewById(R.id.listView1);
Intent i=getIntent();
String st=i.getStringExtra("Bill");
item.setText(st);
try {
db = new DatabaseHelper(this);
//Open the database
expenses = db.getWritableDatabase();
c = expenses.rawQuery("SELECT * FROM Details where Name like"+"'%"+st+"%'", null);
Phno=new String[c.getCount()];
Description=new String[c.getCount()];
Amount=new int[c.getCount()];
if (c != null ) {
if (c.moveToFirst()) {
do {
Phno[j] = c.getString(c.getColumnIndex("Phno"));
//String Name = c.getString(c.getColumnIndex("Name"));
Description[j] = c.getString(c.getColumnIndex("Description"));
Amount[j] = c.getInt(c.getColumnIndex("Amount"));
String Date = c.getString(c.getColumnIndex("Date"));
//String Image=c.getString(c.getColumnIndex("Image"));
arrayList.add("Description :"+Description[j]+"\n"+
"Amount : " +Amount[j] +"\n"+
"Date :"+Date );
j++;
}while (c.moveToNext());
}
}
} catch (SQLiteException se ) {
Log.e(getClass().getSimpleName(),
"Could not create or " +"Open the database");
} finally {
if (expenses != null)
expenses.close();
}
detail.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arrayList));
detail.setOnItemLongClickListener(new OnItemLongClickListener() {
// Called when the user long-clicks on someView
public boolean onItemLongClick (AdapterView parent, View view, int position, long id) {
pos=position;
if (mActionMode != null) {
return false;
}
// Start the CAB using the ActionMode.Callback defined above
mActionMode = SingleItem.this.startActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
}