开发者

How does a ClickListener know which data to return?

I have the following ClickListener:

        itemList=(ListView)findViewById(android.R.id.list);
        itemList.setTextFilterEnabled(true);
        itemList.setOnItem开发者_运维问答ClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                Intent intent = new Intent();
                Bundle b = new Bundle();
                b.putString("TEXT", ((TextView) v).getText().toString());
                intent.putExtras(b);
                setResult(SUCCESS_RETURN_CODE, intent);
                finish();
            }
        });

It worked fine when I used android.R.layout.simple_list_item_1 for the item layout. But when I made a custom layout consisting of the following, it stopped working.

<RelativeLayout>
TextView TextView(this is what I want) TextView
</RelativeLayout>

Edit: It might have something to do with one of the TextViews being clickable?


The view returned in OnItemClickListener is the root View of the clicked item. In your custom layout for listview, it would return the root view of the row ,that is the RelativeLayout. Once you get a hold of the RelativeLayout you can get your desired textview (getChildAt('what ever you want') or query by name or query by id)and get the values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜