Note that there are some explanatory texts on larger screens.

plurals
  1. PO(Android )How can I change the current tab in sub activity?
    primarykey
    data
    text
    <p>As the title, Im writting an app that has four 4 tabs<br> How can I use tabHost.setCurrentTab(3) in tab(SatrtActivity) to go to tab(3)??<br></p> <p>ex: how to declare tabHost as static?? or some else ways :)</p> <p>Here is my code:</p> <pre><code>public class MainActivity extends TabActivity { public static TabHost tabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Resources res = getResources(); tabHost = getTabHost(); TabHost.TabSpec spec; Intent intent; intent = new Intent().setClass(this, StartActivity.class); spec = tabHost.newTabSpec("tab1").setIndicator("Start",res.getDrawable(R.drawable.start)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, WeatherActivity.class); spec = tabHost.newTabSpec("tab2").setIndicator("Weather",res.getDrawable(R.drawable.weather)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, TrafficActivity.class); spec = tabHost.newTabSpec("tab3").setIndicator("Traffic",res.getDrawable(R.drawable.traffic)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, NewsActivity.class); spec = tabHost.newTabSpec("tab4").setIndicator("News",res.getDrawable(R.drawable.price)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); } } public class StartActivity extends Activity{ TextView tempNum, cn1, cn2, cn3, ln1, ln2, ln3; final Handler myHandler = new Handler(); @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView(R.layout.start); tempNum = (TextView) findViewById(R.id.temp); cn1 = (TextView) findViewById(R.id.zone1News1); cn2 = (TextView) findViewById(R.id.zone1News2); cn3 = (TextView) findViewById(R.id.zone1News3); ln1 = (TextView) findViewById(R.id.zone2News1); ln2 = (TextView) findViewById(R.id.zone2News2); ln3 = (TextView) findViewById(R.id.zone2News3); Timer myTimer = new Timer(); myTimer.schedule(new TimerTask() { @Override public void run() {updateInfo();} }, 20000, 5000); } private void updateInfo() { myHandler.post(myRunnable); } final Runnable myRunnable = new Runnable() { public void run() { try{ URL url = new URL("http://xml.weather.yahoo.com/forecastrss?p=TWXX0025&amp;u=c"); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); WeatherHandler weatherHandler = new WeatherHandler(); CentralNewsOneHandler centralNewsOneHandler = new CentralNewsOneHandler(); CentralNewsTwoHandler centralNewsTwoHandler = new CentralNewsTwoHandler(); CentralNewsThreeHandler centralNewsThreeHandler = new CentralNewsThreeHandler(); xr.setContentHandler(weatherHandler); xr.parse(new InputSource(url.openStream())); WeatherParsedDataSet weatherParsedDataSet = weatherHandler.getParsedData(); tempNum.setText(weatherParsedDataSet.toString()); }catch (Exception e) { e.printStackTrace(); } } }; public void setToNewsTab(View view) { tabHost.setCurrentTab(3); //Here is the method that I wanna set to tab(3) } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload