简体   繁体   English

在 listView Android 中添加图像

[英]Add images in listView Android

I'm saving the images name in the database and these images are saved in the drawable, now i want to assign for each item an image from the database according to the item name, i want to compare it with the database.我将图像名称保存在数据库中,这些图像保存在可绘制对象中,现在我想根据项目名称为每个项目从数据库中分配一个图像,我想将其与数据库进行比较。

In database where the image field and the category type (will be retrieved in the list view)在图像字段和类别类型的数据库中(将在列表视图中检索)

and here is the code for retrieving the category type into list view:这是将类别类型检索到列表视图中的代码:

SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.my_profile, c, from, to);  

       ListView list = (ListView) findViewById(R.id.listView1);  

       list.setAdapter(adapter);  
       list.setOnItemClickListener(new OnItemClickListener() {   
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {      

                Intent myIntent = new Intent(view.getContext(), ShowWhereToGo.class); 
                myIntent.putExtra("id", position);
                startActivityForResult(myIntent, 0); // display SubView.class               }
            }

            @SuppressWarnings("unused")
            public void onItemClick1(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub

            }});

}

Thank you in advance :)提前谢谢你:)

您必须创建一个custom list row以在ListView显示图像,您可以参考此链接以更好地理解。

Try creating a custom list.You may refer to the following link:尝试创建自定义列表。您可以参考以下链接:

http://w2davids.wordpress.com/android-listview-with-iconsimages-and-sharks-with-lasers/ http://w2davids.wordpress.com/android-listview-with-iconsimages-and-sharks-with-lasers/

Hope this will help in resolving your trouble :)希望这将有助于解决您的麻烦:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM