How to Display a List of Images in a Listview in Android

I tried to display list of images in Listview but i have only the first item from the list

You can not use a listview in scrollview so Add listview's touch listner to handle scrolling of listview than when you will scroll list you can view all images. So add this listner in CityActivity.java

 listView.setOnTouchListener(new View.OnTouchListener() {
// Setting on Touch Listener for handling the touch inside ScrollView
@Override
public boolean onTouch(View v, MotionEvent event) {
// Disallow the touch request for parent scroll on touch of child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

Display images in listview from Arraylist of uri

Error at this Line.

ImageView imageview = (ImageView)findViewById(R.id.imageView);

change it to,

ImageView imageview = (ImageView) view.findViewById(R.id.imageView);

I Strongly recommend to use ViewHolder Pattern Only. Modify your class.

class CustomAdapter extends BaseAdapter {
@Override
public int getCount() {
return ImageCount;
}

@Override
public Object getItem(int i) {
return null;
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = getLayoutInflater().inflate(R.layout.imagelist_layout, null);
holder.imageview = (ImageView) view.findViewById(R.id.imageView);
view.setTag(holder);
}
else {
holder = (ViewHolder) view.getTag();
}
try {

// getting null exception
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),mArrayUri.get(i));
holder.imageview.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}

return view;
}

class ViewHolder {
private ImageView imageview;
}

}

How to show images efficiently in a list?

If you are using Images, text combination i suggest you look at recycler views. They are much more efficient with images. No harm in using list view, though.

For loading images, use the Picasso library. http://square.github.io/picasso/

You can load images into your image view with just one line of code. Hope this helps.

How to change the image of a list view item when it is clicked in Android Studio?

You need to write view.findViewById and not just findViewById -

Change -

ImageView img=(ImageView) findViewById(R.id.image2);

to

ImageView img=(ImageView) view.findViewById(R.id.image2);

Android display images from url in listview

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

The is an example of fetching and displaying of images using Volley library.

Well the problem is in your ListAdapter. SimpleAdapter just show fields as strings.

Implement your own Adapter with custom view.



Related Topics



Leave a reply



Submit