Android: onListItemClick not opening up the .xml file

Posted by Capsud on Stack Overflow See other posts from Stack Overflow or by Capsud
Published on 2010-05-25T13:51:52Z Indexed on 2010/05/25 14:31 UTC
Read the original article Hit count: 261

Filed under:
|
|

Hi,

 public void onListItemClick(ListView l, View v, int position, long id)
{
    if(position == 0){
        setContentView(R.layout.cuisine);
    }
}

I have an array of Strings and i'm using the above method to try and open up a new xml file called 'cuisine' when it is clicked. but it keeps failing!

Have I done this right, or what am I doing wrong?

Thanks.

Ok from looking at similar problems on the web, people have said to get the onListItemClick() to start a new activity and using that new activity to then open up the new view?

So what i've done is this...

 protected void onListItemClick(ListView l, View v, int position, long id)
{
    Intent dundrumIntent = new Intent(v.getContext(), DundrumSelector.class);
    dundrumIntent.putExtra("position", position);
    startActivityForResult(dundrumIntent, 0);
}

and then

import android.app.Activity;

import android.os.Bundle;

public class DundrumSelector extends Activity { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

    int position = getIntent().getExtras().getInt("position");

    if(position == 0){
        setContentView(R.layout.cuisine);
    }
}

}

Yet i'm still getting the same problem. The program crashes when I click on an item in the listView. And yes i've added the activity to the manifest.

Does anyone have a resolution to this as alot of people seem to be having the same problem.

Thanks alot.

© Stack Overflow or respective owner

Related posts about android

Related posts about listview