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
Difference Between Android-Support-V7-Appcompat and Android-Support-V4
Memory Leaks with Custom Font for Set Custom Font
How to Set Text in an Edittext
Android Runonuithread Explanation
How to Make an Http Request Using Cookies on Flutter
Retrieving a List of Users Who Have Registered Using Firebase Auth
How to Set Android_Home Path in Ubuntu
How to View the Shared Preferences File Using Android Studio
Replace One Fragment with Another in Viewpager
How to Export Library to Jar in Android Studio
Compiling the Latest Openssl for Android
Intent to Launch the Clock Application on Android
Android Mediaplayer Throwing "Prepare Failed.: Status=0X1" on 2.1, Works on 2.2
How to Send Data Back from Onpostexecute in an Asynctask
How to Exclude Certain Messages by Tag Name Using Android Adb Logcat