Note that there are some explanatory texts on larger screens.

plurals
  1. POExpandable listview isn't expanding
    primarykey
    data
    text
    <p>Hi need to prepare screen like this </p> <p><img src="https://i.stack.imgur.com/bBjQY.png" alt="enter image description here"></p> <p>Here is my code of expandable list view</p> <p>Adapter class: <strong>NewAdapter.java</strong> </p> <pre><code>public class NewAdapter extends BaseExpandableListAdapter { public ArrayList&lt;ParentBean&gt; groupItem; ArrayList&lt;String&gt; tempChild; public ArrayList&lt;Object&gt; Childtem = new ArrayList&lt;Object&gt;(); public LayoutInflater minflater; public Activity activity; public NewAdapter(ArrayList&lt;ParentBean&gt; grList, ArrayList&lt;Object&gt; childItem) { groupItem = grList; this.Childtem = childItem; } public void setInflater(LayoutInflater mInflater, Activity act) { this.minflater = mInflater; activity = act; } @Override public Object getChild(int groupPosition, int childPosition) { return null; } @Override public long getChildId(int groupPosition, int childPosition) { return 0; } @Override public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { tempChild = (ArrayList&lt;String&gt;) Childtem.get(groupPosition); TextView text = null; if (convertView == null) { convertView = minflater.inflate(R.layout.childrow, null); } text = (TextView) convertView.findViewById(R.id.textView1); text.setText(tempChild.get(0)); text = (TextView) convertView.findViewById(R.id.textView2); text.setText(tempChild.get(1)); text = (TextView) convertView.findViewById(R.id.textView3); text.setText(tempChild.get(2)); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(activity, tempChild.get(childPosition), Toast.LENGTH_SHORT).show(); } }); return convertView; } @Override public int getChildrenCount(int groupPosition) { return 1; } @Override public Object getGroup(int groupPosition) { return null; } @Override public int getGroupCount() { return groupItem.size(); } @Override public void onGroupCollapsed(int groupPosition) { super.onGroupCollapsed(groupPosition); } @Override public void onGroupExpanded(int groupPosition) { super.onGroupExpanded(groupPosition); } @Override public long getGroupId(int groupPosition) { return 0; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { ViewHolder holder=null; if (convertView == null) { convertView = minflater.inflate(R.layout.grouprow, null); holder = new ViewHolder(); holder.name=(TextView)convertView.findViewById(R.id.playername); holder.team = (TextView) convertView.findViewById(R.id.vs); holder.salary = (TextView) convertView.findViewById(R.id.salary); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ParentBean playerdetails = groupItem.get(groupPosition); holder.name.setText(playerdetails.getPlayername()); holder.team.setText(playerdetails.getPlayerteam()); holder.salary.setText(playerdetails.getPlayersalary()); return convertView; } @Override public boolean hasStableIds() { return false; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } private class ViewHolder { TextView team; TextView name; TextView salary; } class ParentBean{ String playername,playerteam,playersalary; public ParentBean(String playername,String playerteam,String playersalary) { this.playername=playername; this.playersalary=playersalary; this.playerteam=playerteam; } /** * @return the playername */ public String getPlayername() { return playername; } /** * @param playername the playername to set */ public void setPlayername(String playername) { this.playername = playername; } /** * @return the playerteam */ public String getPlayerteam() { return playerteam; } /** * @param playerteam the playerteam to set */ public void setPlayerteam(String playerteam) { this.playerteam = playerteam; } /** * @return the playersalary */ public String getPlayersalary() { return playersalary; } /** * @param playersalary the playersalary to set */ public void setPlayersalary(String playersalary) { this.playersalary = playersalary; } } } </code></pre> <p>Here is my activity : <strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends ExpandableListActivity implements OnChildClickListener { Context context; ArrayList&lt;ParentBean&gt; groupItem = new ArrayList&lt;ParentBean&gt;(); ArrayList&lt;Object&gt; childItem = new ArrayList&lt;Object&gt;(); NewAdapter mNewAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ExpandableListView expandbleLis = getExpandableListView(); expandbleLis.setDividerHeight(2); expandbleLis.setGroupIndicator(null); expandbleLis.setClickable(true); expandbleLis.setFocusable(true); context=this; getData(); mNewAdapter = new NewAdapter(groupItem, childItem); mNewAdapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),this); getExpandableListView().setAdapter(mNewAdapter); expandbleLis.setOnChildClickListener(this); } public void getData() { JsonDataCallback callback=new JsonDataCallback(MainActivity.this) { @Override public void receiveData(Object object) { String jsonData=(String)object; setData(jsonData); } }; callback.execute("http://111.93.7.119:8080/FirstPickService/Players?sportid=fc2e88e6-ac87-4d27-b6b3-863baa9f06ec",null,null); } protected void setData(String jsonData) { try { JSONObject players=new JSONObject(jsonData); final JSONArray playersArray=players.getJSONArray("players"); for(int i=0;i&lt;playersArray.length();i++) { JSONObject jsonObj=playersArray.getJSONObject(i); String teamplayer=jsonObj.getString("playerfullname"); String psalary=jsonObj.getString("playerprice"); String strTeamVS=jsonObj.getString("teamid")+"@"+jsonObj.getString("awayteam"); groupItem.add(mNewAdapter.new ParentBean(teamplayer, psalary, strTeamVS)); String strsalary = jsonObj.getString("playerpricelong"); ArrayList&lt;String&gt; child = new ArrayList&lt;String&gt;(); child.add(psalary); child.add(strTeamVS); child.add(strsalary); childItem.add(child); } mNewAdapter.notifyDataSetChanged(); } catch (Exception e) { e.printStackTrace(); } } @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Toast.makeText(MainActivity.this, "Clicked On Child", Toast.LENGTH_SHORT).show(); return true; } } </code></pre> <p>I am not sure but I have used a button for select, because of that expandable list losing focus and is not showing childrow when click on the listitem...</p>
    singulars
    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.
 

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