如何增加孩子在android的动态tablerow的?孩子、动态、android、tablerow

2023-09-08 09:49:52 作者:永远有多远

我是新来的机器人。我要在动态manner.In添加表行该行我需要添加两个子(TextView的)。但它显示只有一个TextView的只有(第一个)。 这是我的code

 进口android.app.Activity;
进口android.os.Bundle;
进口android.widget.LinearLayout;
进口android.widget.ScrollView;
进口android.widget.TableRow;
进口android.widget.TextView;

公共类DynamicTextView延伸活动{
/ **第一次创建活动时调用。 * /

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    滚动型SV =新的滚动型(本);
    的LinearLayout LL =新的LinearLayout(本);
    ll.setOrientation(LinearLayout.VERTICAL);
    sv.addView(Ⅱ);

    的for(int i = 0;我小于30;我++){
     的TableRow tbrow =新的TableRow(本);
     TextView的TV1 =新的TextView(本);
     tv1.setText(动态的TextView);
     TextView的TV2 =新的TextView(本);
     tv2.setText(否:+一);
     tbrow.addView(TV1);
     tbrow.addView(TV2);
     ll.addView(tbrow);
    }
    的setContentView(SV);

  }
}
 

输出为:

 动态的TextView
   动态的TextView
   动态的TextView
   动态的TextView
   .........
   ..........
 

解决方案

我添加tablelayout.After增加tablerow的欣赏到tablelayout我得到了预期的输出。

  ........
  .........
  TableLayout tblayout =新TableLayout(本);
  tblayout.addView(tbrow);
  ...........
  ..............
 
baby宝贝动态壁纸 baby宝贝动态壁纸安卓版下载

I am new to android. I have to add table row in a dynamic manner.In that row i need to add two child(Textview).But it displays only one textview only(first one). Here is my code

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableRow;
import android.widget.TextView;

public class DynamicTextView extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    sv.addView(ll);

    for(int i=0;i<30;i++){
     TableRow tbrow=new TableRow(this);
     TextView tv1=new TextView(this);
     tv1.setText("Dynamic TextView");
     TextView tv2=new TextView(this);
     tv2.setText(" No : "+i);
     tbrow.addView(tv1);
     tbrow.addView(tv2);
     ll.addView(tbrow);
    }
    setContentView(sv);

  }
}

output is:

   Dynamic TextView
   Dynamic TextView
   Dynamic TextView
   Dynamic TextView
   .........
   ..........

解决方案

I add tablelayout.After adding tablerow view to the tablelayout i got the expected output.

  ........
  .........
  TableLayout tblayout=new TableLayout(this);
  tblayout.addView(tbrow);
  ...........
  ..............