'Separating children from an expandable list
I want to separate the children of the list so that I can assign different individual web links for each one, so far the expandable list generates all the children without a way to individually separate them so that each one could have its own web link. I'm new to android and I've only been doing this for a few months so could someone tell me how I can individually assign a web link to each child because right now every child from the list has the same link assigned to it. Child view of an expandable 2 level list:
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
String childText = (String)getChild(i,i1);
if (view == null)
{
LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.assessment_child_list, null);
}
TextView listC = (TextView)view.findViewById(R.id.listC);
listC.setText(childText);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "https://www.bbc.co.uk/bitesize?id=<package_name>";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
context.startActivity(i);
}
});
return view;
}
Populating the expandable list:
private void initData(){
listP = new ArrayList<>();
listC = new HashMap<>();
listP.add("Week 1-2");
listP.add("Week 3-4");
listP.add("Week 5-6");
listP.add("Week 7-8");
listP.add("Week 9-10");
listP.add("Week 11-12");
List <String> wk1_2 = new ArrayList<>();
wk1_2.add("BBC Bitesize");
wk1_2.add("Google");
List <String> wk3_4 = new ArrayList<>();
wk3_4.add("BBC Bitesize");
List <String> wk5_6 = new ArrayList<>();
wk5_6.add("BBC Bitesize");
List <String> wk7_8 = new ArrayList<>();
wk7_8.add("BBC Bitesize");
List <String> wk9_10 = new ArrayList<>();
wk9_10.add("BBC Bitesize");
List <String> wk11_12 = new ArrayList<>();
wk11_12.add("BBC Bitesize");
listC.put(listP.get(0),wk1_2);
listC.put(listP.get(1),wk3_4);
listC.put(listP.get(2),wk5_6);
listC.put(listP.get(3),wk7_8);
listC.put(listP.get(4),wk9_10);
listC.put(listP.get(5),wk11_12);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
