I have created a gallery, and it displays a lot of images in a horizontal view.
I need 3 buttons for each image below it. I don't know how to create this.
How can I achieve this layout?
This is my expected design:
You could have a custom ListView, and the layout for each element has the image and the buttons. To do that, you need to subclass BaseAdapter and inject this adapter in your ListView.
final BaseAdapter myCustomAdapter = new GalleryAdapter(this);
final ListView gallery = (ListView) findViewById(R.id.gallery);
gallery.setAdapter(myCustomAdapter);
public class GalleryAdapter extends BaseAdapter {
....
implements the class
....
}
Your getView method in the adapter would spawn the layout for individual item, and fill it dynamically with what you want.
Related
public class Exerice_des extends AppCompatActivity {
LinearLayout exerice_dec;
ArrayList<String> arrayList =new ArrayList<>();
Array arrayimage;
Array arraydes;
int ChestImage[] = {R.drawable.pushup,R.drawable.pullup,R.drawable.flatbenchpress,R.drawable.inclinedumbellpress,R.drawable.declinepress,R.drawable.inclinefly,R.drawable.chestdip,R.drawable.armbent};
int Chestdes[]= {R.string.pushup,R.string.pullup,R.string.flatbench,R.string.incline,R.string.decline,R.string.inclinefly,R.string.chestdip,R.string.armbent};
}
}
i want to show this data in one by one
Create a RecyclerView or ListView and the write a custom adapter for it.
To show the image on click either create a new activity or a custom dialog for it
For reference https://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial
I have a custom ListView which is one of the tabs of a viewPager.
public class MyListView extends ListView
I instantiate an object of my class and setEmptyView using
ListView myList = new MyListView(context);
View emptyView = myLayoutInflater().inflate(R.layout.mylist_empty_view, null);
myList.setEmptyView(emptyView);
myList.setAdapter(myAdapter);
However the emptyView never shows up, does not have a parent (which ideally should be the listview) and I cannot see it in the hierarchyViewer. What do I need to do?
AdapterView only manages the visibility of emptyView. If the adapter is empty or null, the visibility of the ListView will be GONE while emptyView is VISIBLE, but to make it show up, you need to add it to the layout yourself.
Just try using this layout
FrameLayout myLayout = new FrameLayout(context);
myLayout.addView(myList);
myLayout.addView(emptyView);
instead of myList directly.
I am implementing a gridview in Android and my requirement is that I want that only 9 items come on 1 page and if there are more than 9 items in a gridview than rest of them should come on the next page. Is it possible??
Thanks
The method that you override to get count in the Custom Image Adapter that extends Base Adapter. This method gives the number of items to be added.
public class ImageAdapter extends BaseAdapter{
#Override
public int getCount() {
return imageList.size();
}
}
Divide your data set into blocks of nine, give the first set of nine to the adapter that you are using for the GridView. Have a Button for next page give the next data set block to the adapter and tell the adapter that the data set has changed.
I have a gallery with a custom adapter. I'm showing an image along with some texts and buttons.
I want to change the texts that are associated with the images when the corresponding buttons are clicked.
If I put the button handler inside the adapter, it doesn't catch the call.
I found out that I should moved the handler to the activity.
But the problem is that I don't have access to the Adapter anymore. Any solutions?
public class MyAdapter extends BaseAdapter { ...
MyGallery myGallery = (MyGallery) findViewById(R.id.mygallery);
myGallery.setAdapter(new MyAdapter(this, ...));
You should set the OnClickListener in the getView function of the adapter. When you inflate the view you can make a call to findViewById on the view to get a reference to the Button. You can then set the OnClickListener on the Button object itself.
Move
MyGallery myGallery = (MyGallery) findViewById(R.id.mygallery);
myGallery.setAdapter(new MyAdapter(this, ...));
into your Activity
Oh yeah and make a member reference to the Adapter eg MyAdapter myAdapter = new MyAdapter(....
This question already has answers here:
How to lazy load images in ListView in Android
(41 answers)
Closed 9 years ago.
What's the way to create a listview with images on the left side and text right after it?
(Note: the images were previously downloaded from the Net)
Thanks in advance!
Here's a complete sample code Lazy load of images in ListView. You can reuse it.
If you have new items in the list you just call adapter.notifyDatasetChanged() and ListView will redisplay all items including the new ones.
The getView() method in adapter inflates item.xml and displays real data in it. You need to start with some basic ListView tutorial, such as the one at Android Series: Custom ListView items and adapters.
A ListView item can have it's own custom layout. When you create your adapter for the ListView you can pass in the layout id to the Adapter constructor. See SimpleAdapter and ArrayAdapter.
=> You will have to extend an Adapter and implement getView() to property set the image+text.
Hi this class is used to make the image to bind with list view use simple adater and use the following class
class MyViewBinder implements ViewBinder {
public boolean setViewValue(View view, Object data,String textRepresentation) {
if( (view instanceof ImageView) & (data instanceof Bitmap) ) {
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
}