1. Download our Official Android App: Forums for Android!

Apps Passing Intents to start Activities

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

  1. rishi360

    rishi360 Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    11
    Joined:
    Jun 5, 2010

    Jun 5, 2010
    11
    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 Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    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...