我有一个数据库,用于存储计数的计数和与该计数相关的名称,我已经获得了列表视图以显示计数,但我无法弄清楚如何显示名称作为子项目。
到目前为止,这是我的代码。
public class SavedScreen extends ListActivity {
TallyDB db = new TallyDB(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_screen);
List<TallyCount> allTallyCounts = db.getAllTallyCounts();
int listSize = allTallyCounts.size();
String[] adapter = new String[listSize];
int i=0;
for (TallyCount tallyCount:allTallyCounts) {
tallyCount.getTally();
tallyCount.getTallyCount();
adapter[i++]=tallyCount.toString();
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_saved_screen, R.id.txtTemplate, adapter));
}
}`
我不太擅长这个但是请原谅我,如果它很简单的话。我尝试使用第二个适配器和for循环来显示名称,但我必须做错了。