我应该如何在这里使用 .setAdapter ? /我如何避免不扩展ListActivity?
我有一个已经扩展 TabActivity 的类,所以我无法扩展 ListActivity。
直到我需要使用此方法之前,这都不是问题:
private static int[] TO = { R.id.catItem, R.id.budgetAmount, };
private void showBudgetOutcome(Cursor cursor) {
//Set up data binding
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, R.layout.itemsforbudgetlist, cursor, FROM, TO);
setListAdapter(adapter);
}
显然 setListAdapter 未定义。现在我发现这段代码正在搜索,
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
但我并不真正理解这些参数。我尝试更改它以适合我:
incomeView.setAdapter(new SimpleCursorAdapter<String>(this, R.layout.itemsforbudgetlist, adapter??));
我看到 mListView 只是用户 ListView,所以我替换了它,并且我猜布局资源定义了列表中每个项目的外观。但其余的我不确定。我想也许我想要一个 Simple/CursorAdapter 因为我正在使用 sqlite (参见我的方法)?但我不知道 COUNTRIES 是什么意思,也不知道我需要什么数据类型(大概是字符串,但我知道什么)。因此,如果有人能为我解决问题并告诉我如何使用上面的方法使用它,我将非常感激!
I have a class that is already extending TabActivity so i can't extend ListActivity.
This hasn't be a problem until i needed to use this method:
private static int[] TO = { R.id.catItem, R.id.budgetAmount, };
private void showBudgetOutcome(Cursor cursor) {
//Set up data binding
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, R.layout.itemsforbudgetlist, cursor, FROM, TO);
setListAdapter(adapter);
}
Obviously setListAdapter is undefined. Now i found this snippet of code searching SO
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
But i don't really understand the parameters. I tried altering it to suit me:
incomeView.setAdapter(new SimpleCursorAdapter<String>(this, R.layout.itemsforbudgetlist, adapter??));
I see that mListView is just the users ListView so i replaced that, and the layout resource defining how each item in the list looks i guess. But the rest i'm not sure about. I figure maybe i want a Simple/CursorAdapter since i'm working with sqlite (see my method)? but i have no idea what COUNTRIES is meant to be and not sure what data type i need (presumably string but what do i know). So if someone could clear things up for me and tell me how to use it with my method above i'd be really greatful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想从数据库中提取数据,你需要子类
CursorAdapter< /代码>
。然后你就可以调用:
If you want to pull your data from a database you need to subclass
CursorAdapter
. Then you can just call: