1. Check out our companion app, Forums for Android! Download from Google Play

Passing Intents to start Activities

Discussion in 'Application Development' started by rishi360, Jul 20, 2010.

  1. rishi360

    rishi360 Member
    Thread Starter
    16

    Jun 5, 2010
    12
    1
    16
    Northern Virginia
    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
    163

    Jul 13, 2010
    1,934
    459
    163
    Male
    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...