java - 在 Android 中创建表格视图的问题
问题描述
我正在尝试编写一个变量表来显示来自 Android 数据库的数据。到目前为止,我可以显示 2 条不同的行,但程序不再创建任何行,我根本找不到错误。
主要活动:
package com.example.tabellentest;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String[] textArray ={" Null "," Eins ", " Zwei ", " Drei ", " Vier ", " Fünf "," SechsHundertZweiUndDreizig ", " Sechs "};
String[] textArray1 ={" 12Null "," 12Eins ", " 12Zwei ", " 12Drei ", " 12Vier ", " 12Fünf "," 12SechsHundertZweiUndDreizig ", " Sechs "};
private TableLayout firstTable;
private TableLayout secondTable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandTextView();
this.firstTable = (TableLayout) findViewById(R.id.tableLayout1);
this.secondTable = (TableLayout) findViewById(R.id.tableLayout2);
ExpandTableRow();
}
public TextView CreateTextView(String text, int index){
TextView textView1 = new TextView(getApplicationContext());
textView1.setText(text);
return textView1;
}
public void ExpandTextView (){
LinearLayout linearLayout = findViewById(R.id.linearLayout1);
for( int i = 0; i < textArray.length; i++ )
{
linearLayout.addView(CreateTextView(textArray[i], i));
TextView textView = new TextView(this);
//textView.setText(textArray[i]);
//textView.setId(i);
linearLayout.addView(textView);
}
}
public void ExpandTableRow(){
for (int ab = 2; ab < 8; ab++){
LinearLayout linearLayout2 = findViewById(R.id.linearLayout2);
for( int i = 0; i < textArray1.length; i++ ) {
linearLayout2.addView(CreateTextView(textArray1[i], i));
}
Context context = getApplicationContext();
TableRow row = new TableRow(context);
secondTable.addView(row);
for( int i = 0; i < textArray1.length; i++ ) {
linearLayout2.addView(CreateTextView(textArray1[i], i));
}
}
}
}
活动主.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</TableRow>
</TableLayout>
</ScrollView>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
我希望任何人都可以给我一个提示以找到问题。
解决方案
推荐阅读
- javascript - 联系表格不向电子邮件发送数据
- google-analytics - 为什么当我选择不同的日期时,来自 Google 分析查询资源管理器的数据会发生变化?
- sql-server - Microsoft Flow:SQL 目标的字符串到 GUID 转换
- android - Activity已经在AndroidManifest.xml中注册了,但是Monkey运行时会出现ActivityNotFoundException
- apache-spark - spark 结构化流 2.3.0 | 阅读 Avro Kafka 主题 | 未找到必需的属性“值”;
- c# - 如何在 Database.EnsureCreated() EF Xamarin.Forms 之后使用 Database.Migration()
- php - 辅助函数在 CodeIgniter 中无法正常工作
- javascript - 使用 karma-electron 时如何改善终端中的 Electron 错误消息?
- animation - 如何为图像的多个实例添加动画?
- java - 无法在 Intellij 中导入的 maven 项目中创建 java 包