Skip to content Skip to sidebar Skip to footer

Listview : Getting The Text Of The Selected Row

I have a listview with an image and a textview in each row. I want to get the value of the text on the clicking of the whole row. Below code is behaving strange.I am getting the va

Solution 1:

You can also try implementing click for listview and get text like this!Hope it works..

listView.setOnItemClickListener(newOnItemClickListener() {
        @OverridepublicvoidonItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            TextViewtext= (TextView) view.findViewById(R.id.title);
            Stringlst_txt= text.getText().toString().trim();
            System.out.println("this is value of string ::: :::: " + lst_txt);
        }
    });

Solution 2:

On your OnClickListener change your code to this:

  vi.setOnClickListener( new View.OnClickListener()
    {


        publicvoidonClick(View v)
        {
              String listValue = (String) data.get(position).get(Meida_listActivity.KEY_TITLE);
              System.out.println("this is value of string ::: :::: " + listValue);

        }


    });

That way you ensure you are referring the correct row.

Solution 3:

type data of variable data is ArrayList

    HashMap<String, String> _hashMap = (HashMap<String, String>) data.get(position);
    String _test = _hashMap.get("Text").toString();

Solution 4:

 vi.setOnClickListener( newView.OnClickListener()
    {
   publicvoidonClick(View v)
        {
     title = (TextView)v.findViewById(R.id.title);
              String listValue = title.getText().toString();
              System.out.println("this is value of string ::: :::: " + listValue);

        }


    });
    return vi;

Solution 5:

add below line listView.setOnItemClickListener(this); and Override onItemClick method. Retrive object on the basis of position(third parameter).

Post a Comment for "Listview : Getting The Text Of The Selected Row"