How to get listitem text in onItemClick listener?

I created a list view and I added some element, can someone help me get the text of the element while listening to the Click element?

lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView <? > parent, View view,
            int position, long id) {
            Object o = parent.getItemAtPosition(position);
            String keyword = o.toString();
            Log.v("value ", "result is " + keyword);

        }
    });

I tried the above code, but it does not work ...

+5
source share
3 answers

I assume you have one TextViewfor the item.

lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView <? > parent, View view,
            int position, long id) {
            TextView txt = (TextView) parent.getChildAt(position - lv.firstVisiblePosition()).findViewById(R.id.mylistviewtextview);
            String keyword = txt.getText().toString();
            Log.v("value ", "result is " + keyword);

        }
    });       

or you can get text from ArrayListwhich you passListView

+8
source

First of all, the correct event to intercept for the selection is onItemSelectedbecause the selection could not be made in the onClick handler. And then the question was well handled by fooobar.com/questions/864385 / ...

+2

All Articles