views:

65

answers:

1

Hi, I am new to android and only have a little experience with HTML and Basic, after much time and frustration I finally managed to make my listview clickable, I made an intent based on position like this;

 if (position == 3) {
                Intent intent = new Intent(this, Bradford.class);
                startActivity(intent);
 }

problem is I have 4 lists in separate tabs and I have 92 options within those lists so I would have to do 92 intents(Very messy), so the first question is, is there a better way of achieving intents with less code whilst still using the position to determine the click

Also I have 92 classes in total they will all do more or less the same, first thing I want to do is put each list category in a folder, does this change the path for instance (this, com.ff.org.firstlist.Bradford.class) do I need to do this in the code or just in the manifest.

Lastly I have 92 classes they will open urls with the app and use gps and some print and image functions would it be better to have all my information in one file instead of separate classes in terms of speed and reliability or should I keep the 92 classes.

A: 

You can group your activities using ActivityGroup. Therefore set the tab content to an ActivityGroup instead of a regular Activity.

tabHost.addTab(tabHost.newTabSpec("Tab")
                .setIndicator("Tab")
                .setContent(new Intent(this, YourActivityGROUP.class)
                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

From within that ActivityGroup you can then start another Activity.

class YourActivityGROUP extends ActivityGroup{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          //you van get the local activitymanager to start the new activity

          View view = getLocalActivityManager()
                                    .startActivity("ReferenceName", new
          Intent(this,YourActivity.class)
                                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                    .getDecorView();
           this.setContentView(view);

       }
    }

Here are some examples: android-tabactivity-nested-activities, experience-multiple-android-activities

ArtWorkAD