I am noob to android development and i want to setContent dynamically for a particular tab. During onCreate i set content as such:
specs2 = th.newTabSpec("tag2");
specs2.setContent(R.id.tab2);
specs2.setIndicator("NEWS",getResources().getDrawable(R.drawable.news));
However, I am having no luck switching the content from a PreferenceActivity. Here is my code:
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String selectednewsfeed = getPrefs.getString("list", "1");
if(selectednewsfeed.contentEquals("1")){
try{
MyActivity.newsfeed.loadUrl("http://feeds.feedburner.com/GoldMoneyGoldResearch");
MyActivity.specs2.setContent(R.id.tab5);
}catch (Exception e){
e.printStackTrace();
}
}
}
I have no issues changing the content within MyActivity, it’s just trying to accomplish this from PreferenceActivity that is the issue. Any help is greatly appreciated.
The easiest approach would be to use startActivityForResult(). This allows you to receive information from the launched activity back in the activity which launched.
Quick example, to launch your PreferenceActivity:
Then inside your PreferenceActivity, set some data to return to MainActivity:
Back inside MainActivity, override onActivityResult():