java - 带有表格读取行的android表格布局

标签 java android android-studio android-tablelayout

我在表格布局中有表格行,我需要读取所有行并将数据移动到 sql。我如何逐行阅读下一行需要阅读第一行并转到第二行并阅读

插入表格行的代码:

TableLayout l1 = (TableLayout) findViewById(R.id.table1);
l1.setStretchAllColumns(true);
l1.bringToFront();

TableRow tr0 = new TableRow(getBaseContext());

TextView tv1 = new TextView(getBaseContext());
TextView tv2 = new TextView(getBaseContext());
TextView tv3 = new TextView(getBaseContext());
TextView tv4 = new TextView(getBaseContext());
TextView tv5 = new TextView(getBaseContext());

tv1.setTextColor(Color.BLACK);
tv2.setTextColor(Color.BLACK);
tv3.setTextColor(Color.BLACK);
tv4.setTextColor(Color.BLACK);
tv5.setTextColor(Color.BLACK);

tv1.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv2.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv3.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv4.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tv5.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

tv1.setText(Integer.toString(id_row=id_row+1));
tv2.setText(e_entrbond_calcname.getText().toString());
tv3.setText(e_entrybonds_mdin1.getText().toString());
tv4.setText(e_entrybonds_dain1.getText().toString());
tv5.setText(e_entrybonds_details2.getText().toString());


tr0.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

tr0.addView(tv1);
tr0.addView(tv2);
tr0.addView(tv3);
tr0.addView(tv4);
tr0.addView(tv5);

l1.addView(tr0);

最佳答案

尝试使用此代码从 TableRow 中读取值;

TableLayout l1 = (TableLayout) findViewById(R.id.table1);

for (int i = 0; i < l1.getChildCount(); i++) {
    View child = l1.getChildAt(i);

    if (child instanceof TableRow) {
        TableRow row = (TableRow) child;

        for (int x = 0; x < row.getChildCount(); x++) {
            //View view = row.getChildAt(x);
            TextView text = (TextView)row.getChildAt(x); // get child index on particular row
            String title = text.getText().toString();
            Log.i("Value", title);      
        }
    }
}

关于java - 带有表格读取行的android表格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42164893/

相关文章:

java - Spring Data Jpa 按方法名称查询无法与 LocalDate 的 BETWEEN 正常工作

java - 你如何处理生成的代码?

java - 使用 xpath 根据标题选择元素时出现问题

java - 如何解决调试问题

android - 为什么出现此错误 “Execution failed for task ':app:compileDebugJavaWithJavac'?

android-studio - 如何在 Android Studio 3.2 中找到工具 -> Android 或等效项以启用 ADB 集成

Java GUI Windows 经典

android - Android 中的声音管理语音识别/TTS

android - 自定义大小的评分栏

java - Fab 按钮 android onClick 导致应用程序崩溃?