gpt4 book ai didi

java - ExpandableListview 中 Childview 中的进度条

转载 作者:行者123 更新时间:2023-12-02 07:18:24 25 4
gpt4 key购买 nike

我正在尝试构建一个应用程序。

我想要的是 expandable ListArrayList<Object> 的每个元素也应该是列表的一个元素。 Parenttitle 应该是对象的标题。该对象还包含 ArrayList<Double>有四个元素。

每位 parent 都应该有一个 child 。父级的子级应显示四个进度条。 ArrayList<Double> 的第一个元素应该设置第一个progressBar的进度等等。

这就是我现在拥有的:

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));

}
}

我在该行收到 NullPointerException

pb1.setProgress(kasten.get(i).getProgress().get(0).intValue());

问题可能是进度条位于布局 list_item_child.xml 中,但此布局不适用于该 Activity 。

有谁知道怎么解决吗?

非常感谢!

(抱歉用词不当;))

最佳答案

您可以通过定义自己的适配器(从 BaseAdapter 扩展)来设置每个单独行中的项目,并在那里定义所有样式参数。您可以在这里找到有关此主题的好教程:http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html

关于java - ExpandableListview 中 Childview 中的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14614399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com