I'm trying to build an App.
What I want is an expandable List
. Every element of an ArrayList<Object>
should be also an element of the List. The Parenttitle should be the object's title. This object also contains an ArrayList<Double>
with four elements.
Every Parent should have one child. The parent's child should display four ProgressBars. The first element of the ArrayList<Double>
should set the progress of the first progressBar and so on.
This is what I have right now:
public class Lernen extends Activity {
private ExpandableListView mExpandableList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lernen);
mExpandableList = (ExpandableListView) findViewById(R.id.expandable_list);
ArrayList<Parent> arrayParents = new ArrayList<Parent>();
ArrayList<String> arrayChildren = new ArrayList<String>();
// MUSS GEÄNDERT WERDEN WENN DIE METHODE GETALLCARDS FERTIG IST!!!
ArrayList<Karteikasten> kasten = new ArrayList<Karteikasten>();
// teststub:
Karteikasten foo = new Karteikasten("Kasten 1");
Karteikasten bar = new Karteikasten("Kasten 2");
kasten.add(bar);
kasten.add(foo);
System.out.println(kasten.size());
try{
// here we set the parents and the children
for (int i = 0; i < kasten.size(); i++) {
System.out.println("Durchlauf: " + i);
System.out.println(kasten.get(0).getProgress().get(0).intValue());
// for each "i" create a new Parent object to set the title and the
// children
Parent parent = new Parent();
parent.setmTitle(kasten.get(i).getName());
arrayChildren.add("Child " + i);
parent.setmArrayChildren(arrayChildren);
ProgressBar pb1 = (ProgressBar) findViewById(R.id.progressBar1);
pb1.setProgress(kasten.get(i).getProgress().get(0).intValue());
ProgressBar pb2 = (ProgressBar) findViewById(R.id.progressBar2);
pb2.setProgress(kasten.get(i).getProgress().get(1).intValue());
ProgressBar pb3 = (ProgressBar) findViewById(R.id.progressBar3);
pb3.setProgress(kasten.get(i).getProgress().get(2).intValue());
ProgressBar pb4 = (ProgressBar) findViewById(R.id.progressBar4);
pb4.setProgress(kasten.get(i).getProgress().get(3).intValue());
System.out.println("Kasten: " + kasten.get(i).getName());
// in this array we add the Parent object. We will use the
// arrayParents at the setAdapter
arrayParents.add(parent);
}
} catch (Exception e){
String stackTrace = Log.getStackTraceString(e);
System.out.println("Fehlermeldung:");
System.out.println(stackTrace);
}
// sets the adapter that provides data to the list.
mExpandableList.setAdapter(new MyExpandableListAdapter(Lernen.this,
arrayParents));
}
}
I get a NullPointerException at the line
pb1.setProgress(kasten.get(i).getProgress().get(0).intValue());
The problem could be, that the progressBar is in the layout list_item_child.xml
, but this layout is not available for the activity.
Does anyone know how to fix it?
Thank you very much!
(And sorry for the bad language ;) )
You can set the items in each individual row by defining your own adapter (extend from BaseAdapter) and define all the styling parameters there. You can find a good tutorial on this topic here: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html
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.