0

I have a list view loaded from an array (used from the tutorial on the android site) and inside the array are class names from other .java files in the same package. What I want it to do is when you click on the item in the list, it loads the java page.

For example, the list item you click would be "foods" and when you click it, it will go to "foods.java"

MyOwnHarem
  • 13
  • 6
  • What have you tried ? Do you know how to start activities using intents? I suggest you read the developer articles first- http://developer.android.com/guide/topics/fundamentals.html – Urban Dec 01 '11 at 23:47
  • Refer to [Looks like a duplicate to][1] [1]: http://stackoverflow.com/questions/8337511/setting-new-pages-linked-by-an-activity/8337745#8337745 – havexz Dec 01 '11 at 23:59

1 Answers1

0

It would be great if you had a little more information, so I'm going to have to assume this is how you're doing it, and if you are, perfect, if not I need a little more insight into your application

String[] activities = {"Foods","Entertainment","Movies","Other"};

listview.setAdapter(...);

Context mContext = this;

listview.setOnItemClickListener(new OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> a, View v, int position, long id) {
   if(position == 0) {
      mContext.startActivity( new Intent(Main.this, Foods.class));
   } else if (position == 1) {
      mContext.startActivity( new Intent(Main.this, Entertainment.class));
   } else if (position == 2) {
      mContext.startActivity( new Intent(Main.this, Movies.class));
   } else if (position == 3) {
      mContext.startActivity( new Intent(Main.this, Other.class));
   }
}
Samuel
  • 4,337
  • 3
  • 29
  • 35
  • This is how mine is set up. `@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter(this, R.layout.list_item, PAGES)); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView> parent, View view, int position, long id) { } }); } static final String[] PAGES = new String[] { "page1", "page2", "page3" };` – MyOwnHarem Dec 02 '11 at 02:40
  • And your code is very helpful, But i'm more of a dynamic man, So all I have to do is add a new activity class and then just add it to the list array. Is there any possible way to do this? – MyOwnHarem Dec 02 '11 at 02:53