简体   繁体   中英

Different Images for each listview item in android

I am building my first app. I want to display a different image for every listview item when I click on it. Can anyone please help me out?

This is the way that I tried in the calling activity.

public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

    locationListView.buildDrawingCache();
    Bitmap image = locationListView.getDrawingCache();

    Bundle extras = new Bundle();
    extras.putParcelable("imagebitmap", image);
    Intent intent;
    intent.putExtras(extras);
    startActivity(intent);


    Bundle extra = getIntent().getExtras();
    Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");

    image.setImageBitmap(bmp);  
}

Have you tried anything yet?

Take a look at these tutorials

http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/

http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92

These will help you accomplish the required task.

Its not much different than creating a regular list view. you just need to modify row.xml file and there are multiple ways to load data into the listview eg JSON array or pull from databaseas explained here http://www.edumobile.org/android/android-programming-tutorials/learn-how-to-create-listview-from-sqlite-database-in-android-development/

Let me know if it works out in the comments , or if u need any additional help

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