• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps adding an image to listview

kiros88

Lurker
Oct 25, 2010
5
0
Hi im wondering if anyone knows if this is possible im trying to create an app that iis a list of stuff and basically i want the user to be able to select one of the listview items and across from the items an image would appear. is this possible if so how do i do it?
 
Your class with have to extend ListActivity, then create a ListView object which allows you to create a list in your parent view.

ListView lv = getListView();

To add images to the list use an ListAdapter and set it to the ListView, this handles adding items to the list. You can then add images from code, such as file paths in an array, or better practice is to be all the images in the res/drawable folder and then access each image via the generated R folder using the images ids.

There is a tutorial on the android developer website List View | Android Developers

Once you have the list you can implement an onOnItemClickListener() which is handles an individually item in the list being pressed. You can run a new Activity and display the full image on another screen or create a toast notification to pop up, though I'm not you can display an image in a Toast.

Hope this is helpful though checking out the tutorial above is your best bet.
 
Upvote 0
the simplest way is to have your javacode as:

Code:
public class JAVAFILENAME extends Activity {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	
    	// Inflate our UI from its XML layout description.
        setContentView(R.layout.YOURXMLFILE);
        
    }
}
and your xml as

Code:
<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none">


<ImageView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/imageview"
      android:background="@drawable/PICTURE"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
</ImageView>

</ScrollView>


This is the simplest way if there is nothing special you want with that image. Don't forget to add the javafile to your manifest.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones