1

I have this ListView setup:

        ListView listView = getListView();
        listView.setTextFilterEnabled(true);

        listView.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int arg2, long id) {

                //

                Intent i = new Intent(getApplicationContext(), Rate.class);
                startActivity(i);

            }
        });

        setListAdapter(new ArrayAdapter<String>(Items.this, R.layout.list,
                items));

It is a standard ListView as you see. Each row has a single TextView populated with the List "items". I am pulling that in from a MySQL Database and outputting through a JSON loop.

I simply want to be able to click on the row, with its single name, and take that name and pass it into the Rate.class activity as a String. How can I do this in code?

4

3 回答 3

2

Add putExtra to your intent (see below). I am assuming you have the list 'items' as the member of the activity, the arg2 argument is basically the index of the item clicked in the list, which you can use to get the name from the 'items' list.

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int arg2, long id) {

            //

            Intent i = new Intent(getApplicationContext(), Rate.class);
            i.putExtra("name", items.get(arg2));
            startActivity(i);

        }
于 2012-06-19T22:51:16.943 回答
0

传递给 onItemClick 的其中一件事是被点击的视图:

将视图转换为适当的类型并调用getText()它;例如:

final String text = ((TextView)view).getText();
于 2012-06-19T22:52:56.090 回答
0

您可以创建一个特定的数组适配器实例,而不仅仅是创建一个传递给函数。然后在OnItemClick()函数中,int arg2 是用户选择的数组适配器中的索引。您可以从数组适配器获取视图,并从文本视图获取 getText()。

于 2012-06-19T22:47:08.470 回答