Passing Intents to start Activities


Last Updated:

  1. rishi360

    rishi360 Member This Topic's Starter

    Joined:
    Jun 5, 2010
    Messages:
    12
    Likes Received:
    1
    Hey guys.

    I'm trying to make a program where you start out with a grid of pictures. I got it working to the point where if you tap one of the pictures, a RelativeLayout with some text (a different activity that uses a separate layout depending on which picture you pressed) opens up. What I CAN'T get to work is to get the grid to open up a GalleryLayout or ListView. Both ways have force closed any time I try to press one of the pictures. I'm passing an Intent and using startActivity() [which worked for the RelativeLayout] but it won't work for RelativeLayout or GalleryLayout.

    Help?

    Thanks!
     

    Advertisement
  2. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    I have never personally used a gallery layout, but for a ListView, have you tried extending ListActivity instead of the usual Activity class?

    the ListActivity class contains all of the functionality of a standard Activity class with some extra implementations for ListViews. It eases the process greatly.

    Here is an example implementation:

    public class MitsuMediaGUI extends ListActivity
    {
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
    super.onListItemClick(l,v,position,id);

    if(position == 0)
    {
    startActivity(new Intent(MitsuMediaGUI.this,RoTM.class));
    }
    ...

    }
    }
     

Share This Page

Loading...