Pieter Tielemans
Pieter Tielemans

Reputation: 624

select a row from a listview from an other class

i want to select the next row position in a list view from an other class but i don't know how to do it. I got the list to pass the position clicked to the other class. in the onItemclick listener

public void onItemClick(AdapterView<?> vie, View view,
                int agr2 , long agr3){

            Intent i = new Intent(context, Test.class);
            i.putExtra("numbers", agr2);
            startActivity(i);
        }

In test.java, i got the value and made the value as

    Bundle extras = getIntent().getExtras();
    int num = extras.getInt("numbers");
    TextView tv = (TextView) findViewById(R.id.textviews);
    int randomb = 1;

    int rand = num - randomb;
    if (rand == -1){
        rand = 100;
    }

    tv.setText("next row to go to :  "+ rand +"  selectedrow :  "+ num );

so my goal is that some how i can put the int "rand" somewhere so it goes to the next row, when lets say i press a button or a timer goes to zero.

thanks in advance.

Upvotes: 1

Views: 81

Answers (3)

Praful Bhatnagar
Praful Bhatnagar

Reputation: 7435

Taking lots of assumption, I think you want to send back the rand to the ListActivity.. so the calling graph would be like following

ListActivity (clicked list item id in intent) --> Randomizer Activity (not sure why u need it) woudl perform some magic and would generate a random variable (you need to pass that back to List activity) --> ListActivity

for this use case you can use startActivityForResult(). please check out the following tutorial:

http://saigeethamn.blogspot.in/2009/08/android-developer-tutorial-for_31.html

EDIT1:

You can also use the setSelection() method to select a particular row..

http://developer.android.com/reference/android/widget/ListView.html#setSelection(int)

Upvotes: 1

Toby D
Toby D

Reputation: 1421

From what I understand, if you want a timer to trigger the event that "go to the next row" then all you should do is just to increase that rand number is your TimerActionListener method and visit the "next row".

Upvotes: 0

Renjith
Renjith

Reputation: 3617

Keep the value of rand in SharedPreferences

You can access the value anywhere in the application and update as and when required.

Hope it helps!

Upvotes: 0

Related Questions