0

Android 开发新手,我正在努力将我的 iOS 应用程序安装到 Android 上。在我的应用程序中,我使用列表视图,效果很好。这就是我到目前为止所拥有的,它在一个 tabwidget 中。

    setListAdapter(new ArrayAdapter<String> (this, R.layout.row_style, ITEMS));
    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

static final String[] ITEMS = new String[] {
    "Apple", "Google", "Hewlett Packard", "Adobe"
};

请注意,ITEMS 字符串数组只是虚拟数据。现在这是我的问题,如果用户单击 Apple 我想启动一个名为 AppleActivity 的活动。我怎么能用 onItemClickListener 做到这一点。在 iphone sdk 我可以打电话

如果(objectAtIndex == 0)

我可以做一些类似的事情吗?希望大家能帮忙。

Jonas :) 请注意,ITEMS 字符串数组只是虚拟数据。现在这是我的问题,如果用户单击 Apple 我想启动一个名为 AppleActivity 的活动。我怎么能用 onItemClickListener 做到这一点。在 iphone sdk 我可以打电话

如果(objectAtIndex == 0)

我可以做一些类似的事情吗?希望大家能帮忙。

乔纳斯:)

4

3 回答 3

0

这是因为您正在尝试启动 Adapter,而 Activity 类必须是 Intent 构造函数的第二个参数。此活动也必须在清单文件中描述。

于 2011-08-01T15:02:20.180 回答
0

是的,你可以,你会有这样的东西->你设置适配器之后

    yourList.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
   //arg2 represents the position , the eletement at arg 2 that is clicked 
   if (arg2==1) startActivity (new Intent ("blabla"));
   if(arg2==2) startActivity (new Intente("Adobeeee"));
   }
于 2011-08-01T12:44:11.053 回答
0
lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            if (position == 0) {
                Intent algebra = new Intent(v.getContext(), AlgebraListViewController.class);
                startActivity(algebra);
            }
            else if (position == 1) {
                Intent oekonomi = new Intent(v.getContext(), OekonomiListViewController.class);
                startActivity(oekonomi);
            }
        }
    });

这应该可以正常工作,重命名变量以便您知道它们是什么(而不是 arg0、arg1、arg2 和 arg3)。

于 2011-08-01T15:16:23.673 回答