简体   繁体   中英

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/

Hope this will help in resolving your trouble :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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