我有一个存储计数计数和与该计数关联的名称的数据库,我已经获得了列表视图来显示计数计数,但我不知道如何将名称显示为子项。
到目前为止,这是我的代码。
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 循环来显示名称,但我一定做错了。