Android Listview:根据sql数据库中的值加载图像(来自记事本教程)
我已经完成了谷歌网页的记事本教程。有以下树字符串:Android Listview:根据sql数据库中的值加载图像(来自记事本教程),android,sql,listview,android-image,Android,Sql,Listview,Android Image,我已经完成了谷歌网页的记事本教程。有以下树字符串: public static final String KEY_TITLE = "title"; public static final String KEY_BODY = "body"; public static final String KEY_ROWID = "_id"; 我只把值“0”、“1”、“2”、“3”放在我的关键字标题中。我希望显示此数组中的图像,而不是在我的Listview的TextView中显示字符串: private i
public static final String KEY_TITLE = "title";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";
我只把值“0”、“1”、“2”、“3”放在我的关键字标题中。我希望显示此数组中的图像,而不是在我的Listview的TextView中显示字符串:
private int icons[] = new int[] {R.drawable.icon1,
R.drawable.icon2, R.drawable.icon3, R.drawable.icon4};
e、 g.如果按键标题为“0”,我想显示图像图标1。等等
现在我有一个问题,SimpleCursorAdapter只能映射到文本视图。我如何告诉SimpleCursorAdapter它必须将字符串值映射到我的icons[]-string中的图标数
有人能帮我写一个新的SimpleCorsorAdapter吗?还是没有必要
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
int[] to = new int[]{R.id.image};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
非常感谢
Felix使用自定义布局,并覆盖bindView嗨,FelixA为什么是SimpleAdapter? 如果我可以建议切换到CustomBasaAdapter,它会为您提供更多的选项以供以后使用,还可以添加图标、图像等。 按照现场说明制作适配器。 你可以在以后调整它,并添加图标,图片等
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results, int[] images) {
super();
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.images = images;
searchArrayList = results;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.test, null);
holder.imgViewLogo =(ImageView)convertView.findViewById(R.id.imgIcon);
....
convertView.setTag(holder);
}
....
holder.imgViewLogo.setImageResource(images[position%4]); // 4 icons to add
公共MyCustomBaseAdapter(上下文上下文、ArrayList结果、int[]图像){
超级();
mInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u充气机\u服务);
这个。图像=图像;
searchArrayList=结果;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
holder=新的ViewHolder();
convertView=mInflater.充气(R.layout.test,空);
holder.imgViewLogo=(ImageView)convertView.findViewById(R.id.imgIcon);
....
convertView.setTag(支架);
}
....
holder.imgViewLogo.setImageResource(图像[位置%4]);//要添加的4个图标