Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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,在我的Android应用程序中,有一个屏幕,其中一些数据将以表格格式显示。此表大约有5列,至少有50行 如何在android中创建表 我搜索了一遍,每个人似乎都建议对每个单元格使用TableLayout和textView。使用这种技术似乎有点困难,因为有很多textView组件 是否有其他解决方案?使用带有自定义适配器的ListView,在ListView项中创建五个textview作为列。。 像这样创建listitem row.xml 用户无需使用TableLayout 您可以使用自定义Lis

在我的Android应用程序中,有一个屏幕,其中一些数据将以表格格式显示。此表大约有5列,至少有50行

如何在android中创建表

我搜索了一遍,每个人似乎都建议对每个单元格使用TableLayout和textView。使用这种技术似乎有点困难,因为有很多textView组件


是否有其他解决方案?

使用带有自定义适配器的ListView,在ListView项中创建五个textview作为列。。 像这样创建listitem row.xml


用户无需使用TableLayout

您可以使用自定义ListView并将ListView的标题设置为列名

要创建自定义列表视图,请参见此

TableLayout lttablelayout;
lTableLayout=(TableLayout)findviewbyd(R.id.tblayout);

对于(int i=0;我想通过?还是通过xml?来编写代码?谢谢你的回答。我会检查它。是否有类似Swing JTable的东西?谢谢你的回答。我可以使用上面的方法创建。但是我想知道如何将特定样式应用于表行,在这种情况下是文本视图。样式在styles.xml中定义。是否可以这样做elp u。背景和文本颜色不是问题。但是当我们从样式或膨胀文本视图中获取属性时,文本视图的宽度没有设置。我想知道为什么单独的宽度不起作用。您可以通过代码为文本视图指定宽度。无需使用样式。我已经为此编辑了我的答案。希望这对您有所帮助。:)谢谢。我只是这样做的。想知道为什么样式中给出的宽度不起作用。于是问。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

   <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
   <TextView android:text="TextView" android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
TableLayout lTableLayout;
lTableLayout = (TableLayout)findViewById(R.id.tblayout);
for(int i=0;i<10;i++){
TableRow tr1 = new TableRow(this);
tr1.setPadding(0, 5, 0, 0);
lTableLayout.addView(tr1, LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
TextView tv11 = new TextView(this);
tv11.setPadding(2, 0, 0, 0);
tv11.setTextSize(12);
tr1.addView(tv11,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); // Can give width and height in numbers also.

}
<TableLayout
                    android:id="@+id/tblayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
</TableLayout>