Mario L
Mario L

Reputation: 224

I can not get the items of a listview

I have two textview in my hola.xml file, I want to show is the first (0). thanks

TextView t = (TextView) findViewById(R.id.textViewNMAT1);
String foo = ((TextView)((ViewGroup) arg1).getChildAt(0)).getText().toString();
t.setText(foo);

Upvotes: 0

Views: 85

Answers (1)

codeMagic
codeMagic

Reputation: 44571

Change to

    @Override
    public void onItemClick(AdapterView<?> infoM, View arg1, int posicion, long _id)
    {
        TextView t = (TextView) findViewById(R.id.textViewNMAT1);
        String foo = ((TextView)arg1).getText().toString();

        t.setText(foo);
    }

the first param is the object that holds the Adapter info (Spinner, ListView, etc...) and the second param is the View which was clicked (here a TextView). So get the text which is in that TextView.

Docs

Upvotes: 2

Related Questions