Note that there are some explanatory texts on larger screens.

plurals
  1. PORefresh whole parent of expandablelistview
    primarykey
    data
    text
    <p>I can't get a custom layout in expandablelistview to work, that refreshes on a click of a child child.</p> <p>In the example you have the method MyExpandableListAdapter -> getChildView, where the child inflates a custom layout R.layout.list_out_item (what is some textviews and buttons).</p> <p>Now I want that if I click a button that the child and parent of that childview is updated. How can I achieve this? I was thinking about refreshing the parent and child, because collapsing forces an update, but other solutions are also welcome.</p> <p>For an example</p> <pre><code>public class Sample extends ExpandableListActivity { ExpandableListAdapter mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up our adapter mAdapter = new MyExpandableListAdapter(); setListAdapter(mAdapter); } } public class MyExpandableListAdapter extends BaseExpandableListAdapter { private Map&lt;Ability, Integer&gt; abilityMods; private List&lt;Skill&gt; skills = SkillList(); private List&lt;Skill&gt; SkillList() { List&lt;Skill&gt; skills = new Vector&lt;Skill&gt;(); abilityMods = Player.getAbilityModifier(); skills.add(new Skill(abilityMods, "Appraise", 2, Ability.Dex, 2)); skills.add(new Skill(abilityMods, "Autohypnosis", 0, Ability.Int, -7)); skills.add(new Skill(abilityMods, "Craft", 0, Ability.Dex, 0)); return skills; } public MyExpandableListAdapter() { super(); abilityMods = Player.getAbilityModifier(); } public long getChildId(int groupPosition, int childPosition) { return childPosition; } public int getChildrenCount(int groupPosition) { return 1; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) { LayoutInflater infalInflater = getLayoutInflater(); convertView = infalInflater.inflate(R.layout.list_out_item, null); final Skill skill = getChild(groupPosition, childPosition); TextView tv = (TextView) convertView.findViewById(R.id.abilityMod); tv.setText(toString(skill.abillityMod())); Button rankMod = (Button) convertView.findViewById(R.id.rankMod); rankMod.setText(toString(skill.Ranks)); rankMod.setOnClickListener(new OnClickListener() { public void onClick(View v) { skill.Ranks++; } }); return convertView; } private String toString(int value) { if (value &gt;= 0) return ("+" + String.valueOf(value)); else return (String.valueOf(value)); } public Skill getGroup(int groupPosition) { return skills.get(groupPosition); } @Override public Skill getChild(int groupPosition, int childPosition) { return getGroup(groupPosition); } public int getGroupCount() { return skills.size(); } public long getGroupId(int groupPosition) { return groupPosition; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { LayoutInflater infalInflater = getLayoutInflater(); convertView = infalInflater .inflate(R.layout.list_header_item, null); TextView skillName = (TextView) convertView .findViewById(R.id.skillName); Skill skill = getGroup(groupPosition); TextView skillPower = (TextView) convertView .findViewById(R.id.skillPower); int TotalMod = skill.TotalModifier(); if (TotalMod &gt;= 0) skillPower.setText("+" + String.valueOf(TotalMod)); else skillPower.setText(String.valueOf(TotalMod)); return convertView; } public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public boolean hasStableIds() { return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload