0

I have created one listview of some names,what i need is when i will click selected row it will go to that page only,on click on different row it will move to the same class but different content.I think it will move by question id.could anybody help me how to pass the question id Or any other method to do this..

here is my code..

private OnItemClickListener mlist = new OnItemClickListener(){

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {


    }       
};
  • You mean same activity with multiple sections? – Anukool Feb 15 '13 at 10:01
  • @Anukool no i mean if i will click one name it will move to another page have the description of that name.. –  Feb 15 '13 at 10:02
  • Have a look at [this](http://stackoverflow.com/a/9647042/593709) post to pass data from ListView to next Activity. [this post](http://stackoverflow.com/a/8352538/593709) is also good. and specially [google](https://www.google.com.pk/search?q=android+passing+data+to+another+activity). – Adil Soomro Feb 15 '13 at 10:06
  • @AdilSoomro thanks ..but i need that when i will click any row it will move to that particular rowpage only.. –  Feb 15 '13 at 10:09

2 Answers2

0

You can try something like this -

private OnItemClickListener mlist = new OnItemClickListener(){

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

        if(Some condition)
        {
            Intent i= new Intent(YourActivity.this,ActivityOne.class);
            // To pass data 
            i.putExtra("SomeId", someValue);
            startActivity(i);
        }
        else if(Some other condition)
        {
            Intent i= new Intent(YourActivity.this,SecondActivityTwo.class);
            startActivity(i);
        }
        else
        {
            // Do something else--
        }

    }       
};

And in the other activity -

String identifier = getIntent().getExtras().getString("SomeId");
Anukool
  • 5,301
  • 8
  • 29
  • 41
  • i want that suppose you click first row it will move to aaa.class..next if you will click third row it should move to aaa.class with different content ..by passing userid..or something –  Feb 15 '13 at 10:19
  • @ Sangita : you will have to explain a little more . – Anukool Feb 15 '13 at 10:30
  • k..look..i have a 10 list row..on each row onclick..it will display some content..which willbe in listview also –  Feb 15 '13 at 10:33
  • @ Sangita : On Click are you populating a new ListView ? Or You are talking about the nested listviews? – Anukool Feb 15 '13 at 10:34
  • on row onclick it will show some custom listview which will be having the content of the row only.. –  Feb 15 '13 at 10:37
-1

Here I've given an example assuming you have user list and clicking on item you want to show user profile...

In List_Act activity...

public View getView(int position, View convertView, ViewGroup parent)
{
    convertView = mInflater.inflate(R.layout.rowitem,parent,false);

    convertView.setTag(UserId);
}

private OnItemClickListener mlist = new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Intent i=new Intent(List_Act.this, Profile_Act.class);
            int UserId = ((View)v.getParent()).getTag();
            i.putExtra("UserId", UserId);  //Setting variable you want to pass to another activity
            startActivity(i);
        }       
    };

in Profile_Act activity in onCreate()

String UserId = getIntent().getExtras().getString("UserId");  //retrieving value in another activity

now you'll have UserId variable set and you can use it...

Mohit Mehta
  • 1,283
  • 12
  • 21
  • @Sangita yes you'll have to assign tag to the item in getView() of adapter class, this tag should be id of the user or something you wanna pass... and in the onclick method you can get the tag id and pass... – Mohit Mehta Feb 15 '13 at 10:22
  • @Sangita now check... in the getView method I've set the tag for the list item... – Mohit Mehta Feb 15 '13 at 10:32
  • i have already create base adapter ..i need to pass the name id from one activity to another –  Feb 15 '13 at 10:35
  • @Sangita yes in the class extended by BaseAdepter you would have overrided method public View getView(int position, View convertView, ViewGroup parent) in this method you can set tag as I've mentioned, and in onclick you can retrieve value from the tag and using putExtra you can pass it... – Mohit Mehta Feb 15 '13 at 10:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24561/discussion-between-mohit-mehta-and-sangita) – Mohit Mehta Feb 15 '13 at 10:43
  • sorry..i can not accept your answer is fine..but finally it is not working –  Feb 15 '13 at 14:20
  • @Sangita It's ok... I could have solved it if you could sent me the sample code – Mohit Mehta Feb 15 '13 at 14:23