我在外部存储中创建了数据库,并且已经为表中的每个步骤存储了图像路径和音频路径。现在从一个新的Android应用程序我想访问表并提取自定义列表视图与图像和文本。图像以表格形式存储在字符串中。如何在自定义列表视图中获取图像和视图?
答案 0 :(得分:0)
static DisplayImageOptions op;
static ImageLoader loader = ImageLoader.getInstance();
在你的onCreate
op = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer(20)).cacheOnDisc(true)
.considerExifParams(true).build();
ListView list = (ListView) findViewById(R.id.customwhateverlist);
String query = "SELECT * FROM YOURTABLE with whatever you want ";
Cursor cursor = sqLiteDatabase.rawQuery(query, null);
((ListView) list).setAdapter(new MyCallitwhatyouwillAdapter(context,cursor, 0));
THEN ...
private static final class MyCallItWhatYouWillAdapter extends CursorAdapter {
MyCallitwhatyouwillAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater.inflate(R.layout.SOMECOOLLAYOUT, parent, false);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView iv = (ImageView) view.findViewById(R.id.YOURIMAGETHINGEE);
//FOR IMAGELOADER YOU MUST HAVE "_id" INTEGER PRIMARY KEY" in database!!!
TextView blah = (TextView) view.findViewById(R.id._id);
blah.setText(cursor.getString(cursor.getColumnIndex("SomethingNiceColumn")));
loader.init(ImageLoaderConfiguration.createDefault(context));
loader.displayImage(cursor.getString(cursor.getColumnIndex("SavedPathToImage")), iv, op);
}
LayoutInflater mInflater;
}
您需要将imageloader添加为库。你可以在这里得到它。 https://github.com/nostra13/Android-Universal-Image-Loader