2014-03-05 117 views
0

我的屏幕有4个带有tablelayout的选项卡。当我询问SQLite的数据时,该选项卡是由ugt值选择的。Tabview内容重叠

ugt等于1或2时,现在有问题 - 数据在tab1和tab2之间分开并且正常显示。

但是当ugt等于3或4时,数据显示在所有4个选项卡上!数据与其他数据重叠。

下面是代码:

 while (cursor2.moveToNext()) { 
      int id = cursor2.getInt(cursor2.getColumnIndex(LeaderBase.UID)); 
      String name = cursor2.getString(cursor2.getColumnIndex(LeaderBase.USERNAME)); 
      String money = String.valueOf(cursor2.getLong(cursor2.getColumnIndex(LeaderBase.USERMONEY))); 
      String speed = String.valueOf(cursor2.getLong(cursor2.getColumnIndex(LeaderBase.USERSPEED))); 
      String time = String.valueOf(cursor2.getLong(cursor2.getColumnIndex(LeaderBase.USERTIME))); 
      int ugt = (int)cursor2.getLong(cursor2.getColumnIndex(LeaderBase.UGAMETYPE)); 


      TableRow row = null; 
      switch(ugt){ 
     case 1: 
      row = (TableRow)inflater.inflate(R.layout.tablerow, tl1, false); 
      break; 
     case 2: 
      row = (TableRow)inflater.inflate(R.layout.tablerow, tl2, false); 
      break; 
     case 3: 
      row = (TableRow)inflater.inflate(R.layout.tablerow, tl3, false); 
      break; 
     case 4: 
      row = (TableRow)inflater.inflate(R.layout.tablerow, tl4, false); 
      break; 
     } 
      TextView tv1 = (TextView)row.findViewById(R.id.textView1); 
      TextView tv2 = (TextView)row.findViewById(R.id.textView2); 
      TextView tv3 = (TextView)row.findViewById(R.id.textView3); 
      TextView tv4 = (TextView)row.findViewById(R.id.textView4); 

      tv1.setText(name); 
      tv2.setText(money); 
      tv3.setText(time); 
      tv4.setText(speed); 

      switch(ugt){ 
      case 1: 
       tl1.addView(row); 
       break; 
      case 2: 
       tl2.addView(row); 
       break; 
      case 3: 
       tl3.addView(row); 
       break; 
      case 4: 
       tl4.addView(row); 
       break; 
      } 

     } 

这里是一个屏幕截图。 enter image description here 感谢您的回答!

回答

0

我找到了解决方案。我选择了如下标签内容:

TabHost.TabSpec spec1 = tabs.newTabSpec("tag1"); 
    spec1.setContent(R.id.tab1); 
    spec1.setIndicator("Без времени"); 
    tabs.addTab(spec1); 

但tab1在ScrollView1中。所以我改变了所有的字符串

spec1.setContent(R.id.tab1); 

spec1.setContent(R.id.ScrollView1); 
0

我认为在你的开关块中输入默认值是因为ugt中的意外值。请检查您定义ugt的代码,或者您需要像这样在交换机中添加默认值。

switch(ugt){ 
    case 1: 
     //some code; 
     break; 
    case 2: 
     //some code; 
     break; 
    case 3: 
     //some code; 
     break; 
    case 4: 
     //some code; 
     break; 
    default: 
     //deafult code that happens when ugt is not the value from the other cases. 
     break; 
} 

打印出ugt的值,以便您确切知道。

+0

完成 - 问题依旧 –

+0

什么是UGT的输出? – Oya

+0

输出正确(1,2,3或4)。有时甚至每个选项卡中的第一行都会重叠移位和混合(我的意思是标题) –