Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式向表中添加列_Android_Android Tablelayout - Fatal编程技术网

Android 以编程方式向表中添加列

Android 以编程方式向表中添加列,android,android-tablelayout,Android,Android Tablelayout,我在以编程方式向表中添加列时遇到了一些麻烦,可能我查找/搜索了错误的关键字,但找不到合适的解决方案 我得到了这个密码: ScrollView sv = new ScrollView(this); TableLayout ll=new TableLayout(this); HorizontalScrollView hsv = new HorizontalScrollView(this); TableRow tbrow=new TableRo

我在以编程方式向表中添加列时遇到了一些麻烦,可能我查找/搜索了错误的关键字,但找不到合适的解决方案

我得到了这个密码:

 ScrollView sv = new ScrollView(this);

         TableLayout ll=new TableLayout(this);
         HorizontalScrollView hsv = new HorizontalScrollView(this);
         TableRow tbrow=new TableRow(this);
         for(int i=0;i<mConnector.idArray.size();i++) {
             tbrow=new TableRow(this);         

                 TextView tv1=new TextView(this);
                 //String s1 = Integer.toString(i);
                 try {
                String insecticide = mConnector.insecticideArray.get(i);
                String wegedoornuis = mConnector.wegedoornluisArray.get(i);
                String dosering = mConnector.doseringArray.get(i);
                String prijs = mConnector.prijsArray.get(i);
                String bestuivers = mConnector.bestuiversArray.get(i);
                String roofvijanden = mConnector.roofvijandenArray.get(i);                    

               // String result = insecticide +" | "+wegedoornuis+" | "+dosering+" | "+prijs+" | "+bestuivers+" | "+roofvijanden;
               // int id = Integer.parseInt(s3);
                 tv1.setId(i);

                 tv1.setText(id);
                 tbrow.addView(tv1);
                 }catch(java.lang.IndexOutOfBoundsException e){

                 }

             ll.addView(tbrow);
         }
         hsv.addView(ll);
         sv.addView(hsv);
         setContentView(sv);
ScrollView sv=新的ScrollView(此);
TableLayout ll=新的TableLayout(本);
HorizontalScrollView hsv=新的HorizontalScrollView(此);
TableRow tbrow=新的TableRow(本);

对于(int i=0;i您不能直接将字符串添加到视图中,但您可以使用文本视图来执行相同的操作。我将向您展示一个我曾经做过的示例,并让您了解如何为自己使用而执行此操作

        TableRow row=new TableRow(this.getApplicationContext());
        TableLayout tlayout=new TableLayout(this.getApplicationContext());

        tlayout.setGravity(Gravity.CENTER);
        tlayout.setBackgroundResource(R.color.background);

        row=new TableRow(this);

        TextView text1=new TextView(this.getApplicationContext());
        TextView text2=new TextView(this.getApplicationContext());
        TextView text3=new TextView(this.getApplicationContext());

        text1.setText(R.string.name);
        row.addView(text1);
        text2.setText(R.string.level);
        row.addView(text2);
        text3.setText(R.string.score);
        row.addView(text3);
        tlayout.addView(row);
        for (i=0;i<10;i++)
        {
            row=new TableRow(this.getApplicationContext());
            text1=new TextView(this.getApplicationContext());
            text2=new TextView(this.getApplicationContext());
            text3=new TextView(this.getApplicationContext());


            text1.setText(high_score_name.get(i));
            row.addView(text1);
            text2.setText(""+high_score_level.get(i));
            row.addView(text2);
            text3.setText(""+high_score_score.get(i));
            row.addView(text3);
            tlayout.addView(row);
        }

如果我看到这一点,
row.addView
是一列?基本上,这将显示3列数据,每个
TextView
都有一列。啊,好吧,但还有最后一件事。谷歌说一列也是一行不是有点愚蠢吗?(我就是这样读的)。我的意思是一列和一行是两个不同的东西。本质上,row.addView是向该行添加新视图。由于只有一行,它会向该行添加一个新列。然后完成该行,并将其添加到表中。
name1  score1  level1
name2  score2  level2