Nemka
Nemka

Reputation: 100

Get a text on an Item using OnItemClickListener

I have a ListView with an adapter

enter image description here

And I want to use the implemented method to go on another activity(SendSmsActivity.class):

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

                viewCampagneId = (TextView)findViewById(R.id.idCampagne);
                final String theCampagneId = viewCampagneId.getText().toString();

                viewCampagneName = (TextView)findViewById(R.id.nomCampagne);
                final String theCampagneName = viewCampagneName.getText().toString();

                Intent i = new Intent(RecupXml_Activity.this,SendSmsActivity.class);
                i.putExtra("ID", theCampagneId);
                i.putExtra("name", theCampagneName);
                startActivity(i);

            }

The SendSmsActivity.class will download an xml according to the ID in the textview2. for example : If I click on the item "campagne22" it will go to another activity and load an xml at http://blabla/?id="**22**" So I have to get the text in textview2 to put the value ID in a PutExtra (so activity2 can catch it)

How can I do it ?

With my actual code above, it doesn't work, it save the item at the top of the view not the one I selected..

PS : It seems I don't really know how the arguments in the method onItemClickListener works..

Upvotes: 0

Views: 284

Answers (1)

Jens Zalzala
Jens Zalzala

Reputation: 2576

The second argument in onItemClick() is the view you clicked on, so to get the containing textView, you can use

viewCampagneId = (TextView) arg1.findViewById(R.id.idCampagne);
viewCampagneName = (TextView) arg1.findViewById(R.id.nomCampagne);

Upvotes: 1

Related Questions