开发者

How to do an onListItemClick?

开发者 https://www.devze.com 2023-04-06 05:59 出处:网络
I have an Activity and I want to do a setOnListItemClick on my Listview but I seem unable to do it. I am only able to do it with ListActivity but I need an EditText so I can\'t use the ListActivity.

I have an Activity and I want to do a setOnListItemClick on my Listview but I seem unable to do it.

I am only able to do it with ListActivity but I need an EditText so I can't use the ListActivity.

Can anyone help me?

public v开发者_运维问答oid onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    

    listview = (ListView) findViewById(R.id.listview);
    edittext = (EditText) findViewById(R.id.search_box);

    arrayA = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, eventTitle);
    setListAdapter(arrayA);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    // Get the item that was clicked

}


When you use a listactivity youcan use other layout elements and views. The only rule is, there must be a listview with an id as @android:id/list. Here's the doc explaining it clearly. So there should be nothing preventing you from using an edittext in an listactivity. Are you having doubt's on creating a xml layout with an edittext and listview?

0

精彩评论

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

关注公众号