GridView inside ExpandableLisView in Android
I hope GridView inside ExpandableLisView like this.
This is my code :
MainActivity.java:
private List<List<String>> itemList; //child's data
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
ExpandableListViewAdapter.java:
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
gridView = (GridView) convertView;
MyGridViewAdapter gridViewAdapter = new MyGridViewAdapter(context, itemList.get(groupPosition));
gridView.setAdapter(gridViewAdapter);
MyGridViewAdapter.java
List<String> itemGridList;
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.gridview_item, null);
}
TextView item_name = (TextView) convertView.findViewById(R.id.item_name);
ImageView item_icon = (ImageView) convertView.findViewById(R.id.item_icon);
item_name.setText(itemGridList.get(position));
item_icon.setImageResource(item_icon.get(position)); //get error?
}
I don't know why item_icon.setImageResource
will get error ?
what I am missing?
Update :
MyGridViewAdapter.java
int imageId; //add
item_icon.setImageResource(imageId[position]);
but I get NullPointerException
I try to show imageviews in MainActivity , this is my data :
private List<List<String>> itemList;
List<String> groupList = initData();
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
elv.setAdapter(adapter);
private List<String> initData() {
List<String> groupList = new ArrayList<>();
List<String> itemGridList1 = new ArrayList<>();
String item1 = getResources().getStringArray(R.array.sport);
itemGridList1.add(item1[0]);
itemGridList1.add(item1[1]);
List<String> itemGridList2 = new ArrayList<>();
String item2 = getResources().getStringArray(R.array.healthy);
itemGridList2.add(item2[0]);
itemGridList2.add(item2[1]);
itemList = new ArrayList<>();
itemList.add(itemGridList1);
itemList.add(itemGridList2);
return groupList;
}
Update :
ExpandableListActivity.java
private int logos = new int { R.drawable.fitness, R.drawable.walking, R.drawable.temp };
private String generalsTypes = new String { "Sport", "Healthy", "Measure" };
private String generals = new String {
{"Swimming", "Hiking", "Climbing", "Biking"},
{"Walking" , "Running"},
{"Measure"}
};
private int generallogos = new int{
{ R.drawable.ic_swimming, R.drawable.ic_hiking, R.drawable.ic_climbing, R.drawable.ic_bike },
{ R.drawable.ic_walk, R.drawable.ic_running },
{ R.drawable.ic_matters }
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(adapter);
elv.setGroupIndicator(null);
}
ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
@Override
public int getGroupCount() {
return generalsTypes.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return generals[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return generalsTypes[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return generals[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView logo = new ImageView(ExpandableListActivity.this);
logo.setImageResource(logos[groupPosition]);
logo.setPadding(50, 0, 0, 0);
ll.addView(logo);
TextView textView = getTextView();
textView.setTextColor(Color.BLACK);
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView generallogo = new ImageView(
ExpandableListActivity.this);
generallogo
.setImageResource(generallogos[groupPosition][childPosition]);
ll.addView(generallogo);
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
ll.addView(textView);
return ll;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
};
I hope like this :
GridView with ImageView
android gridview imageview expandablelistview
|
show 8 more comments
I hope GridView inside ExpandableLisView like this.
This is my code :
MainActivity.java:
private List<List<String>> itemList; //child's data
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
ExpandableListViewAdapter.java:
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
gridView = (GridView) convertView;
MyGridViewAdapter gridViewAdapter = new MyGridViewAdapter(context, itemList.get(groupPosition));
gridView.setAdapter(gridViewAdapter);
MyGridViewAdapter.java
List<String> itemGridList;
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.gridview_item, null);
}
TextView item_name = (TextView) convertView.findViewById(R.id.item_name);
ImageView item_icon = (ImageView) convertView.findViewById(R.id.item_icon);
item_name.setText(itemGridList.get(position));
item_icon.setImageResource(item_icon.get(position)); //get error?
}
I don't know why item_icon.setImageResource
will get error ?
what I am missing?
Update :
MyGridViewAdapter.java
int imageId; //add
item_icon.setImageResource(imageId[position]);
but I get NullPointerException
I try to show imageviews in MainActivity , this is my data :
private List<List<String>> itemList;
List<String> groupList = initData();
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
elv.setAdapter(adapter);
private List<String> initData() {
List<String> groupList = new ArrayList<>();
List<String> itemGridList1 = new ArrayList<>();
String item1 = getResources().getStringArray(R.array.sport);
itemGridList1.add(item1[0]);
itemGridList1.add(item1[1]);
List<String> itemGridList2 = new ArrayList<>();
String item2 = getResources().getStringArray(R.array.healthy);
itemGridList2.add(item2[0]);
itemGridList2.add(item2[1]);
itemList = new ArrayList<>();
itemList.add(itemGridList1);
itemList.add(itemGridList2);
return groupList;
}
Update :
ExpandableListActivity.java
private int logos = new int { R.drawable.fitness, R.drawable.walking, R.drawable.temp };
private String generalsTypes = new String { "Sport", "Healthy", "Measure" };
private String generals = new String {
{"Swimming", "Hiking", "Climbing", "Biking"},
{"Walking" , "Running"},
{"Measure"}
};
private int generallogos = new int{
{ R.drawable.ic_swimming, R.drawable.ic_hiking, R.drawable.ic_climbing, R.drawable.ic_bike },
{ R.drawable.ic_walk, R.drawable.ic_running },
{ R.drawable.ic_matters }
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(adapter);
elv.setGroupIndicator(null);
}
ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
@Override
public int getGroupCount() {
return generalsTypes.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return generals[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return generalsTypes[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return generals[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView logo = new ImageView(ExpandableListActivity.this);
logo.setImageResource(logos[groupPosition]);
logo.setPadding(50, 0, 0, 0);
ll.addView(logo);
TextView textView = getTextView();
textView.setTextColor(Color.BLACK);
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView generallogo = new ImageView(
ExpandableListActivity.this);
generallogo
.setImageResource(generallogos[groupPosition][childPosition]);
ll.addView(generallogo);
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
ll.addView(textView);
return ll;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
};
I hope like this :
GridView with ImageView
android gridview imageview expandablelistview
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20
|
show 8 more comments
I hope GridView inside ExpandableLisView like this.
This is my code :
MainActivity.java:
private List<List<String>> itemList; //child's data
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
ExpandableListViewAdapter.java:
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
gridView = (GridView) convertView;
MyGridViewAdapter gridViewAdapter = new MyGridViewAdapter(context, itemList.get(groupPosition));
gridView.setAdapter(gridViewAdapter);
MyGridViewAdapter.java
List<String> itemGridList;
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.gridview_item, null);
}
TextView item_name = (TextView) convertView.findViewById(R.id.item_name);
ImageView item_icon = (ImageView) convertView.findViewById(R.id.item_icon);
item_name.setText(itemGridList.get(position));
item_icon.setImageResource(item_icon.get(position)); //get error?
}
I don't know why item_icon.setImageResource
will get error ?
what I am missing?
Update :
MyGridViewAdapter.java
int imageId; //add
item_icon.setImageResource(imageId[position]);
but I get NullPointerException
I try to show imageviews in MainActivity , this is my data :
private List<List<String>> itemList;
List<String> groupList = initData();
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
elv.setAdapter(adapter);
private List<String> initData() {
List<String> groupList = new ArrayList<>();
List<String> itemGridList1 = new ArrayList<>();
String item1 = getResources().getStringArray(R.array.sport);
itemGridList1.add(item1[0]);
itemGridList1.add(item1[1]);
List<String> itemGridList2 = new ArrayList<>();
String item2 = getResources().getStringArray(R.array.healthy);
itemGridList2.add(item2[0]);
itemGridList2.add(item2[1]);
itemList = new ArrayList<>();
itemList.add(itemGridList1);
itemList.add(itemGridList2);
return groupList;
}
Update :
ExpandableListActivity.java
private int logos = new int { R.drawable.fitness, R.drawable.walking, R.drawable.temp };
private String generalsTypes = new String { "Sport", "Healthy", "Measure" };
private String generals = new String {
{"Swimming", "Hiking", "Climbing", "Biking"},
{"Walking" , "Running"},
{"Measure"}
};
private int generallogos = new int{
{ R.drawable.ic_swimming, R.drawable.ic_hiking, R.drawable.ic_climbing, R.drawable.ic_bike },
{ R.drawable.ic_walk, R.drawable.ic_running },
{ R.drawable.ic_matters }
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(adapter);
elv.setGroupIndicator(null);
}
ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
@Override
public int getGroupCount() {
return generalsTypes.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return generals[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return generalsTypes[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return generals[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView logo = new ImageView(ExpandableListActivity.this);
logo.setImageResource(logos[groupPosition]);
logo.setPadding(50, 0, 0, 0);
ll.addView(logo);
TextView textView = getTextView();
textView.setTextColor(Color.BLACK);
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView generallogo = new ImageView(
ExpandableListActivity.this);
generallogo
.setImageResource(generallogos[groupPosition][childPosition]);
ll.addView(generallogo);
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
ll.addView(textView);
return ll;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
};
I hope like this :
GridView with ImageView
android gridview imageview expandablelistview
I hope GridView inside ExpandableLisView like this.
This is my code :
MainActivity.java:
private List<List<String>> itemList; //child's data
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
ExpandableListViewAdapter.java:
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
gridView = (GridView) convertView;
MyGridViewAdapter gridViewAdapter = new MyGridViewAdapter(context, itemList.get(groupPosition));
gridView.setAdapter(gridViewAdapter);
MyGridViewAdapter.java
List<String> itemGridList;
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = View.inflate(context, R.layout.gridview_item, null);
}
TextView item_name = (TextView) convertView.findViewById(R.id.item_name);
ImageView item_icon = (ImageView) convertView.findViewById(R.id.item_icon);
item_name.setText(itemGridList.get(position));
item_icon.setImageResource(item_icon.get(position)); //get error?
}
I don't know why item_icon.setImageResource
will get error ?
what I am missing?
Update :
MyGridViewAdapter.java
int imageId; //add
item_icon.setImageResource(imageId[position]);
but I get NullPointerException
I try to show imageviews in MainActivity , this is my data :
private List<List<String>> itemList;
List<String> groupList = initData();
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(MainActivity.this, groupList, itemList);
elv.setAdapter(adapter);
private List<String> initData() {
List<String> groupList = new ArrayList<>();
List<String> itemGridList1 = new ArrayList<>();
String item1 = getResources().getStringArray(R.array.sport);
itemGridList1.add(item1[0]);
itemGridList1.add(item1[1]);
List<String> itemGridList2 = new ArrayList<>();
String item2 = getResources().getStringArray(R.array.healthy);
itemGridList2.add(item2[0]);
itemGridList2.add(item2[1]);
itemList = new ArrayList<>();
itemList.add(itemGridList1);
itemList.add(itemGridList2);
return groupList;
}
Update :
ExpandableListActivity.java
private int logos = new int { R.drawable.fitness, R.drawable.walking, R.drawable.temp };
private String generalsTypes = new String { "Sport", "Healthy", "Measure" };
private String generals = new String {
{"Swimming", "Hiking", "Climbing", "Biking"},
{"Walking" , "Running"},
{"Measure"}
};
private int generallogos = new int{
{ R.drawable.ic_swimming, R.drawable.ic_hiking, R.drawable.ic_climbing, R.drawable.ic_bike },
{ R.drawable.ic_walk, R.drawable.ic_running },
{ R.drawable.ic_matters }
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(adapter);
elv.setGroupIndicator(null);
}
ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
@Override
public int getGroupCount() {
return generalsTypes.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return generals[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return generalsTypes[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return generals[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView logo = new ImageView(ExpandableListActivity.this);
logo.setImageResource(logos[groupPosition]);
logo.setPadding(50, 0, 0, 0);
ll.addView(logo);
TextView textView = getTextView();
textView.setTextColor(Color.BLACK);
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(
ExpandableListActivity.this);
ImageView generallogo = new ImageView(
ExpandableListActivity.this);
generallogo
.setImageResource(generallogos[groupPosition][childPosition]);
ll.addView(generallogo);
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
ll.addView(textView);
return ll;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
};
I hope like this :
GridView with ImageView
android gridview imageview expandablelistview
android gridview imageview expandablelistview
edited Nov 27 '18 at 6:59
Tzuyu Lin
asked Nov 26 '18 at 6:41
Tzuyu LinTzuyu Lin
55
55
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20
|
show 8 more comments
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20
|
show 8 more comments
3 Answers
3
active
oldest
votes
item_icon
is an ImageView
Object and it is given integer value which is located in R.java
file.
I thing you are doing mistake to get integer
resource for Image to be shown in ImageView
Try with below code.
item_icon.setImageResource(--put here some actual resources--);
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
|
show 1 more comment
private List<String> Group;
private List<List<String>> Child;
private List<String> Child_1;
private List<String> Child_2;
private List<String> Child_3;
private List<List<Integer>> ChildPicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Group = new ArrayList<String>();
Group.add("SPORT");
Group.add("Healthy");
Group.add("Measure");
Child_1 = new ArrayList<String>();
Child_1.add("Swimming");
Child_1.add("Biking");
Child_1.add("Hiking");
Child_2 = new ArrayList<String>();
Child_2.add("Walking");
Child_2.add("Running");
Child_3 =new ArrayList<String>();
Child_3.add("Measure");
Child = new ArrayList<List<String>>();
Child.add(Child_1);
Child.add(Child_2);
Child.add(Child_3);
List<Integer> ChildPic_1 = new ArrayList<Integer>();
ChildPic_1.add(R.drawable.ic_swimming);
ChildPic_1.add(R.drawable.ic_bike);
ChildPic_1.add(R.drawable.ic_hiking);
List<Integer> ChildPic_2 = new ArrayList<Integer>();
ChildPic_2.add(R.drawable.ic_walk);
ChildPic_2.add(R.drawable.ic_running);
List<Integer> ChildPic_3 = new ArrayList<Integer>();
ChildPic_3.add(R.drawable.ic_matters);
ChildPicture = new ArrayList<List<Integer>>();
ChildPicture.add(ChildPic_1);
ChildPicture.add(ChildPic_2);
ChildPicture.add(ChildPic_3);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(new MyExpandableAdapter(Main2Activity.this));
elv.setGroupIndicator(null);
}
the reasult is :ExpandableListView child with imageView and TextView
but I still find out that child is gridView or gridLayout ....
add a comment |
item_icon is not a list Right? So how can you get the position from item_icon?
you have
List<String> itemGridList;
as the list that you are passing to the item_name
Similarly you should have a list for the images to be shown
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475908%2fgridview-inside-expandablelisview-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
item_icon
is an ImageView
Object and it is given integer value which is located in R.java
file.
I thing you are doing mistake to get integer
resource for Image to be shown in ImageView
Try with below code.
item_icon.setImageResource(--put here some actual resources--);
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
|
show 1 more comment
item_icon
is an ImageView
Object and it is given integer value which is located in R.java
file.
I thing you are doing mistake to get integer
resource for Image to be shown in ImageView
Try with below code.
item_icon.setImageResource(--put here some actual resources--);
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
|
show 1 more comment
item_icon
is an ImageView
Object and it is given integer value which is located in R.java
file.
I thing you are doing mistake to get integer
resource for Image to be shown in ImageView
Try with below code.
item_icon.setImageResource(--put here some actual resources--);
item_icon
is an ImageView
Object and it is given integer value which is located in R.java
file.
I thing you are doing mistake to get integer
resource for Image to be shown in ImageView
Try with below code.
item_icon.setImageResource(--put here some actual resources--);
edited Nov 26 '18 at 7:03
answered Nov 26 '18 at 6:54
Chetan JoshiChetan Joshi
4,01021826
4,01021826
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
|
show 1 more comment
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
this looks same as the above code that @Tzuyu Lin gave
– ABr
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
@ABr Check onces again'
– Chetan Joshi
Nov 26 '18 at 6:56
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
Didn't get you !! @Chetan Joshi
– ABr
Nov 26 '18 at 6:58
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
If you don't understand why you comment on me.
– Chetan Joshi
Nov 26 '18 at 6:59
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
Hey! I just asked to clarify.
– ABr
Nov 26 '18 at 7:01
|
show 1 more comment
private List<String> Group;
private List<List<String>> Child;
private List<String> Child_1;
private List<String> Child_2;
private List<String> Child_3;
private List<List<Integer>> ChildPicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Group = new ArrayList<String>();
Group.add("SPORT");
Group.add("Healthy");
Group.add("Measure");
Child_1 = new ArrayList<String>();
Child_1.add("Swimming");
Child_1.add("Biking");
Child_1.add("Hiking");
Child_2 = new ArrayList<String>();
Child_2.add("Walking");
Child_2.add("Running");
Child_3 =new ArrayList<String>();
Child_3.add("Measure");
Child = new ArrayList<List<String>>();
Child.add(Child_1);
Child.add(Child_2);
Child.add(Child_3);
List<Integer> ChildPic_1 = new ArrayList<Integer>();
ChildPic_1.add(R.drawable.ic_swimming);
ChildPic_1.add(R.drawable.ic_bike);
ChildPic_1.add(R.drawable.ic_hiking);
List<Integer> ChildPic_2 = new ArrayList<Integer>();
ChildPic_2.add(R.drawable.ic_walk);
ChildPic_2.add(R.drawable.ic_running);
List<Integer> ChildPic_3 = new ArrayList<Integer>();
ChildPic_3.add(R.drawable.ic_matters);
ChildPicture = new ArrayList<List<Integer>>();
ChildPicture.add(ChildPic_1);
ChildPicture.add(ChildPic_2);
ChildPicture.add(ChildPic_3);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(new MyExpandableAdapter(Main2Activity.this));
elv.setGroupIndicator(null);
}
the reasult is :ExpandableListView child with imageView and TextView
but I still find out that child is gridView or gridLayout ....
add a comment |
private List<String> Group;
private List<List<String>> Child;
private List<String> Child_1;
private List<String> Child_2;
private List<String> Child_3;
private List<List<Integer>> ChildPicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Group = new ArrayList<String>();
Group.add("SPORT");
Group.add("Healthy");
Group.add("Measure");
Child_1 = new ArrayList<String>();
Child_1.add("Swimming");
Child_1.add("Biking");
Child_1.add("Hiking");
Child_2 = new ArrayList<String>();
Child_2.add("Walking");
Child_2.add("Running");
Child_3 =new ArrayList<String>();
Child_3.add("Measure");
Child = new ArrayList<List<String>>();
Child.add(Child_1);
Child.add(Child_2);
Child.add(Child_3);
List<Integer> ChildPic_1 = new ArrayList<Integer>();
ChildPic_1.add(R.drawable.ic_swimming);
ChildPic_1.add(R.drawable.ic_bike);
ChildPic_1.add(R.drawable.ic_hiking);
List<Integer> ChildPic_2 = new ArrayList<Integer>();
ChildPic_2.add(R.drawable.ic_walk);
ChildPic_2.add(R.drawable.ic_running);
List<Integer> ChildPic_3 = new ArrayList<Integer>();
ChildPic_3.add(R.drawable.ic_matters);
ChildPicture = new ArrayList<List<Integer>>();
ChildPicture.add(ChildPic_1);
ChildPicture.add(ChildPic_2);
ChildPicture.add(ChildPic_3);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(new MyExpandableAdapter(Main2Activity.this));
elv.setGroupIndicator(null);
}
the reasult is :ExpandableListView child with imageView and TextView
but I still find out that child is gridView or gridLayout ....
add a comment |
private List<String> Group;
private List<List<String>> Child;
private List<String> Child_1;
private List<String> Child_2;
private List<String> Child_3;
private List<List<Integer>> ChildPicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Group = new ArrayList<String>();
Group.add("SPORT");
Group.add("Healthy");
Group.add("Measure");
Child_1 = new ArrayList<String>();
Child_1.add("Swimming");
Child_1.add("Biking");
Child_1.add("Hiking");
Child_2 = new ArrayList<String>();
Child_2.add("Walking");
Child_2.add("Running");
Child_3 =new ArrayList<String>();
Child_3.add("Measure");
Child = new ArrayList<List<String>>();
Child.add(Child_1);
Child.add(Child_2);
Child.add(Child_3);
List<Integer> ChildPic_1 = new ArrayList<Integer>();
ChildPic_1.add(R.drawable.ic_swimming);
ChildPic_1.add(R.drawable.ic_bike);
ChildPic_1.add(R.drawable.ic_hiking);
List<Integer> ChildPic_2 = new ArrayList<Integer>();
ChildPic_2.add(R.drawable.ic_walk);
ChildPic_2.add(R.drawable.ic_running);
List<Integer> ChildPic_3 = new ArrayList<Integer>();
ChildPic_3.add(R.drawable.ic_matters);
ChildPicture = new ArrayList<List<Integer>>();
ChildPicture.add(ChildPic_1);
ChildPicture.add(ChildPic_2);
ChildPicture.add(ChildPic_3);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(new MyExpandableAdapter(Main2Activity.this));
elv.setGroupIndicator(null);
}
the reasult is :ExpandableListView child with imageView and TextView
but I still find out that child is gridView or gridLayout ....
private List<String> Group;
private List<List<String>> Child;
private List<String> Child_1;
private List<String> Child_2;
private List<String> Child_3;
private List<List<Integer>> ChildPicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Group = new ArrayList<String>();
Group.add("SPORT");
Group.add("Healthy");
Group.add("Measure");
Child_1 = new ArrayList<String>();
Child_1.add("Swimming");
Child_1.add("Biking");
Child_1.add("Hiking");
Child_2 = new ArrayList<String>();
Child_2.add("Walking");
Child_2.add("Running");
Child_3 =new ArrayList<String>();
Child_3.add("Measure");
Child = new ArrayList<List<String>>();
Child.add(Child_1);
Child.add(Child_2);
Child.add(Child_3);
List<Integer> ChildPic_1 = new ArrayList<Integer>();
ChildPic_1.add(R.drawable.ic_swimming);
ChildPic_1.add(R.drawable.ic_bike);
ChildPic_1.add(R.drawable.ic_hiking);
List<Integer> ChildPic_2 = new ArrayList<Integer>();
ChildPic_2.add(R.drawable.ic_walk);
ChildPic_2.add(R.drawable.ic_running);
List<Integer> ChildPic_3 = new ArrayList<Integer>();
ChildPic_3.add(R.drawable.ic_matters);
ChildPicture = new ArrayList<List<Integer>>();
ChildPicture.add(ChildPic_1);
ChildPicture.add(ChildPic_2);
ChildPicture.add(ChildPic_3);
ExpandableListView elv = findViewById(R.id.expenview);
elv.setAdapter(new MyExpandableAdapter(Main2Activity.this));
elv.setGroupIndicator(null);
}
the reasult is :ExpandableListView child with imageView and TextView
but I still find out that child is gridView or gridLayout ....
edited Nov 28 '18 at 9:39
answered Nov 28 '18 at 9:34
Tzuyu LinTzuyu Lin
55
55
add a comment |
add a comment |
item_icon is not a list Right? So how can you get the position from item_icon?
you have
List<String> itemGridList;
as the list that you are passing to the item_name
Similarly you should have a list for the images to be shown
add a comment |
item_icon is not a list Right? So how can you get the position from item_icon?
you have
List<String> itemGridList;
as the list that you are passing to the item_name
Similarly you should have a list for the images to be shown
add a comment |
item_icon is not a list Right? So how can you get the position from item_icon?
you have
List<String> itemGridList;
as the list that you are passing to the item_name
Similarly you should have a list for the images to be shown
item_icon is not a list Right? So how can you get the position from item_icon?
you have
List<String> itemGridList;
as the list that you are passing to the item_name
Similarly you should have a list for the images to be shown
edited Nov 26 '18 at 7:01
answered Nov 26 '18 at 6:54
ABrABr
331211
331211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475908%2fgridview-inside-expandablelisview-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
List<Integer> list1 = new ArrayList(); list1.add(R.drawable.tick); holder.img_status.setImageResource(list1.get(position));
– ABr
Nov 26 '18 at 9:00
Or try it like this ---> int l; l = new int{R.drawable.tick,R.drawable.tick}; holder.img_status.setImageResource(l[position]);
– ABr
Nov 26 '18 at 9:11
@ABr , Can I just modify MainActivity only ? itemGridList1.add("swimming", R.deawable.pic01); it seems more easy?
– Tzuyu Lin
Nov 26 '18 at 9:48
Whats this groupList and itemList inside MainActivity? Can you please explain the use of private List<List<String>> itemList? Do you reallly require a List<List>?
– ABr
Nov 26 '18 at 10:05
Actually what you need is a String and a corresponding Drawable am i Right?
– ABr
Nov 26 '18 at 10:20