こんにちは。
b
Ta Hostを知らないことが原因だと思われる問題を解決していただければ幸いです。
ビジュアル コンポーネントがまったく同じで、同じ ID を持つ 3 つのタブを持つタブホストを持ち、選択したタブとして値を与えることは可能ですか?
たとえば、3 つのタブで 3 つをEditExt
呼び出しています。
R.id.textNivel1Acierto
R.id.textNivel1Objetivo
R.id.textNivel1Fallo
3 つのタブで同じ ID を使用できますか? 私が欲しいのは、これら3つTextView
がタブに応じて異なる値を示すことです
私が試したいくつかのことをコードに入れましたが、タブをクリックすると現在失敗しているため、思い通りに機能しないと言いました
public class Resultados extends Activity {
TabHost tabs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultados);
tabs=(TabHost)findViewById(android.R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tabSumas");
spec.setContent(R.id.tabSumas);
spec.setIndicator("", this.getResources().getDrawable(R.drawable.boton_suma));
tabs.addTab(spec);
spec=tabs.newTabSpec("tabRestas");
spec.setContent(R.id.tabRestas);
spec.setIndicator("", this.getResources().getDrawable(R.drawable.boton_resta));
tabs.addTab(spec);
spec=tabs.newTabSpec("tabAritmetica");
spec.setContent(R.id.tabAritmetica);
spec.setIndicator("", this.getResources().getDrawable(R.drawable.boton_aritmetica));
tabs.addTab(spec);
tabs.setCurrentTab(0);
// TextView tAciertos = (TextView) findViewById(R.id.textNivel1Acierto);
// TextView tFallos = (TextView) findViewById(R.id.textNivel1Fallo);
// TextView tObjetivo = (TextView) findViewById(R.id.textNivel1Objetivo);
// tAciertos.setText("0");
// tFallos.setText("0");
// tObjetivo.setText("0");
tabs.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if (tabId.equals("tabSumas"))
{
cambiaValores(0, "0");
// TextView tAciertos=(TextView) tabs.getTabWidget().getChildAt(0).findViewById(R.id.textNivel1Acierto);
// TextView tFallos=(TextView) tabs.getTabWidget().getChildAt(0).findViewById(R.id.textNivel1Fallo);
// TextView tObjetivo=(TextView) tabs.getTabWidget().getChildAt(0).findViewById(R.id.textNivel1Objetivo);
// tAciertos.setText("0");
// tFallos.setText("0");
// tObjetivo.setText("0");
}else if (tabId.equals("tabRestas"))
{
// TextView tAciertos=(TextView) tabs.getTabWidget().getChildAt(1).findViewById(R.id.textNivel1Acierto);
// TextView tFallos=(TextView) tabs.getTabWidget().getChildAt(1).findViewById(R.id.textNivel1Fallo);
// TextView tObjetivo=(TextView) tabs.getTabWidget().getChildAt(1).findViewById(R.id.textNivel1Objetivo);
// tFallos.setText("1");
// tObjetivo.setText("1");
// tAciertos.setText("1");
cambiaValores(1, "1");
}else if (tabId.equals("tabAritmetica"))
{
// TextView tAciertos=(TextView) tabs.getTabWidget().getChildAt(2).findViewById(R.id.textNivel1Acierto);
// TextView tFallos=(TextView) tabs.getTabWidget().getChildAt(2).findViewById(R.id.textNivel1Fallo);
// TextView tObjetivo=(TextView) tabs.getTabWidget().getChildAt(2).findViewById(R.id.textNivel1Objetivo);
// tAciertos.setText("2");
// tFallos.setText("2");
// tObjetivo.setText("2");
cambiaValores(2, "2");
}
}
});
}
public void cambiaValores(int iD, String texto)
{
TextView tAciertos=(TextView) tabs.getTabWidget().getChildAt(iD).findViewById(R.id.textNivel1Acierto);
TextView tFallos=(TextView) tabs.getTabWidget().getChildAt(iD).findViewById(R.id.textNivel1Fallo);
TextView tObjetivo=(TextView) tabs.getTabWidget().getChildAt(iD).findViewById(R.id.textNivel1Objetivo);
tAciertos.setText(texto);
tFallos.setText(texto);
tObjetivo.setText(texto);
}
}
public class extends TabActivity Results
「 」または「 」をより良くするには、もう 1 つ必要public class Result extends Activity
ですか?
私が間違っていることを教えていただければ幸いです ありがとう