I would like to create a Pop-Out dialog which will be similar like above picture. All the button will have the text from a List of texts and when any specific button is pressed the respective image should load in the Image section below.
For example: I have the JSON data like shown below, Once the user clicks Apple
button the Image section below should load the link https://test.com/images/apple.jpg . Any idea or tutorial to achieve this?
"Fruit": [
{
"Title": "Apple",
"ImageURL": "https://test.com/images/apple.jpg"
},
{
"Title": "Orange",
"ImageURL": "https://test.com/images/orange.jpg"
},
{
"Title": "Banana",
"ImageURL": "https://test.com/images/banana.jpg"
},
{
"Title": "Watermelon",
"ImageURL": "https://test.com/images/watermelon.jpg"
},
{
"Title": "Strawberry",
"ImageURL": "https://test.com/images/strawberry.jpg"
}
add button into Linear layout using for loop Like this.
LinearLayout layout=(LinearLayout )findViewById(R.id.layout);
for(int i=0;i<fruitList.size();i++)
{
final Button button = new Button(this);
button.setText(fruitList.get(i).getName());
button.setId(i);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position=button.getId();
imageView.setImageURI(fruitList.get(position).getImage());
}
});
layout.addView(button);
}
here is github library instand of linear layout you can use FlexboxLayout of this library to add multiple row with button. https://github.com/google/flexbox-layout
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.