Android ListView list_item load another page

1k views Asked by At

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"

1

There are 1 answers

2
Samuel On BEST ANSWER

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));
   }
}