Tushar Chutani
Tushar Chutani

Reputation: 1560

android listview and intent

I am new to android development. I just wanted to know how can I access variables (for example textview variable) in the class we are navigating to so that I can change the value of it depending on the listview tapped.

here is a bit of code

    protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);



        Intent openStartingPoint = new Intent("com.name.MainClass");

        startActivity(openStartingPoint);}

thanks

Upvotes: 0

Views: 485

Answers (1)

Jacob Nordfalk
Jacob Nordfalk

Reputation: 3533

Most robust way of doing that is to put the information in the Intent.

Change to

   Intent openStartingPoint = new Intent(this, com.name.MainClass.class);
   openStartingPoint.putExtra("position", position);
    startActivity(openStartingPoint);}

and in the recieving activity's onCreate you write:

   Intent openStartingPoint = getIntent();
   int position = openStartingPoint.getIntExtra("position");

Upvotes: 2

Related Questions