您好,我想构建一个 Android 应用程序来处理我的预算。我之前构建了一个预算应用程序,但它是在 WPF 中和 C# 中。在 WPF 中有一个叫做 DataGrid 的东西看起来像这样
https://www.codeproject.com/KB/WPF/WPFDataGridExamples/datasetgrid.png (我不允许发布图片)
我想知道 Android 中是否有类似的东西,可以向用户显示信息表。
谢谢。
最佳答案
public class MainActivity extends AppCompatActivity {
// i used this array list for quick purpose
// better way to use data models
private String[][] gradingData = new String[][]{
{"S.N", "Range", "Grading", "Description", "GP"},
{"1", "90-100", "A+", "Outstanding", "4.0"},
{"2", "80-90", "A", "Excellent", "3.6"},
{"3", "70-80", "B+", "Very Good", "3.2"},
{"4", "60-70", "B", "Good", "2.8"},
{"5", "50-60", "C", "Average", "2.4"},
{"6", "Below 50", "D", "Below Average", "2.0"},
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout parentLayout = findViewById(R.id.parentLayout);
parentLayout.addView(createTableLayout(7, 5));
}
private TableLayout createTableLayout(int rowCount, int columnCount) {
// 1) Create a tableLayout and its params
TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams();
TableLayout tableLayout = new TableLayout(this);
// tableLayout.setBackgroundColor(Color.BLACK);
// 2) create tableRow params
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams();
tableRowParams.weight = 1;
for (int i = 0; i < rowCount; i++) {
// 3) create tableRow
TableRow tableRow = new TableRow(this);
// tableRow.setBackgroundColor(Color.BLACK);
for (int j = 0; j < columnCount; j++) {
// 4) create textView
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
textView.setPadding(10, 10, 10, 10);
textView.setBackground(getResources().getDrawable(R.drawable.textview_border));
textView.setText(gradingData[i][j]);
if (i == 0) {
textView.setBackgroundColor(Color.parseColor("#aeaeae"));
}
tableRow.addView(textView, tableRowParams);
}
tableLayout.addView(tableRow, tableLayoutParams);
}
return tableLayout;
}
}
关于java - 安卓数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47627714/