Java Android:TabHost和修改值textedit
下午好 我希望你能帮我解决一个问题,我猜是由于不了解TaJava Android:TabHost和修改值textedit,java,android,android-tabhost,Java,Android,Android Tabhost,下午好 我希望你能帮我解决一个问题,我猜是由于不了解TabHost引起的 有可能有一个具有3个选项卡的tabhost,其中视觉组件完全相同,具有相同的ID,并将它们作为所选选项卡赋予值 例如,在3个选项卡中,我调用了三个EditExt R.id.textNivel1Acierto R.id.textNivel1Objetivo R.id.textNivel1Fallo 你能在3个标签中有相同的ID吗? 我想要的是,这3个TextView根据选项卡显示不同的值 我把代码和我一直在尝试的一些东
b
Host引起的
有可能有一个具有3个选项卡的tabhost,其中视觉组件完全相同,具有相同的ID,并将它们作为所选选项卡赋予值
例如,在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
”或更好地使用“public class Result extends Activity
”
我希望你能告诉我我错了
谢谢如果你有三个相同的标签,那么为什么要使用3个不同的ID来显示标签内容?因为它们不太适合tabhost,相信它做得很好。我认为每个标签都应该有一个不同的ID。当然我知道我会使用9 textview(每个标签3个)不会有问题,但只能使用3个?所有选项卡中的设计都是相同的,只需更改显示的信息,不知道我是否进行了解释,例如我是否希望tab1脉冲到位(仅举一个例子,我将读取值(对于数据库)好的:1错误:1次:1如果我按下tab2好的:2坏的:2次:2脉冲如果tab3好的:3坏的:3次:3这是可能的。发布活动的布局文件。好的,这就是布局,也许这不是最好的方式。。该布局是一个6行4列的“表格”,但。。每次重复id时,都会显示一条警告。。例如:重复id@+id/textNivel5Objetivo,已在此布局中定义。谢谢你的时间放一个链接的布局,因为它超过30000个字符