I am having a real hard time on putting my activities in tabs. I have an activity that parses an XML file and puts them on a list, and it works perfectly on its own. When I call it on a tab however it does not work (i get the dreaded "Sorry! blah blah.. has stopped unexpectedly" prompt... BTW yes I did the manifest).
I have migrated the activities to work as one activity, voila! it worked!!! However this is not the way we wanted to go with this project - WE REALLY NEED to have separate activities.
So as many people had found out that tabs and activities doesn't work well together is there a way to work around it? Some sort of emulsifier maybe?
Here is the code:
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.Toast;
public class TabDemo extends Activity{
/** data members go here*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
TabHost tabs= (TabHost)findViewById(R.id.tabhost);
tabs.setup();
Intent callResultHits = new Intent(this, my.tabebd.layout.ResultHits.class);
TabHost.TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(callResultHits);
spec.setIndicator("Result", getResources().getDrawable(R.drawable.ic_tab_search_result) );
tabs.addTab(spec);
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Details",getResources().
getDrawable(R.drawable.ic_tab_details));
tabs.addTab(spec);
tabs.setCurrentTabByTag("tag1");
} catch (Throwable t) {
// TODO Auto-generated catch block
Toast.makeText(this, "Exception: " + t.toString(), 50000).show();
}
}
here is one of the activities...
public class ResultHits extends Activity implements OnItemClickListener {
ListView listView_titles;
ArrayList<String> items = new ArrayList<String>();
String [] test = {"1", "2","3"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView_titles = (ListView)findViewById(R.id.list);
listView_titles.setAdapter(new ArrayAdapter<String>
(this,R.layout.row, R.id.row_text,test));
}
}
I omitted the xml parsing part... if this basic list can be shown inside the tab then it will be perfect. TY in advance
BTW setcurrenttabByTag was previously setCurrenttab(2)..actualy i did these values 0,1, 2, 3 just in case ;)