我应该如何在这里使用 .setAdapter ? /我如何避免不扩展ListActivity?

发布于 2024-10-05 11:12:31 字数 928 浏览 0 评论 0原文

我有一个已经扩展 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隐诗 2024-10-12 11:12:32

如果你想从数据库中提取数据,你需要子类 CursorAdapter< /代码>。然后你就可以调用:

incomeView.setAdapter(new MyCursorAdapter(WhatEver arguments, You need));

If you want to pull your data from a database you need to subclass CursorAdapter. Then you can just call:

incomeView.setAdapter(new MyCursorAdapter(WhatEver arguments, You need));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文