Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically updating TabWidget icons?
    primarykey
    data
    text
    <p>Is it possible to update the TabWidget icons/indicators? If so, how, when you are creating TabContent through intents?</p> <p>Edits below with answer thanks to @Bart</p> <p>Generic code:</p> <p>MainActivity:</p> <pre><code>public class TestActivity extends TabActivity { public int i; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost); TabHost mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab1").setContent( new Intent(this, OneActivity.class)).setIndicator("One")); mTabHost.addTab(mTabHost.newTabSpec("tab2").setContent( new Intent(this, TwoActivity.class)).setIndicator("Two")); changeTitle(0, 20); } public void changeTitle(int cnt, int i){ View v = getTabWidget().getChildAt(cnt); TextView tv = (TextView) v.findViewById(android.R.id.title); tv.setText("One ("+i+")"); } </code></pre> <p>}</p> <p>OneActivity (ChildActivity):</p> <pre><code>public class OneActivity extends Activity { TextView tv; Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.one); tv = (TextView) findViewById(R.id.tv); btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int i = Integer.parseInt((String) tv.getText()); i++; tv.setText(""+i); TestActivity parent = OneActivity.this.getParent(); parent.changeTitle(0,i); } }); } </code></pre> <p>}</p> <p>I'd like to show the number in the Tab's title</p>
    singulars
    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