我有一个带有一些按钮和 TextView(称为 Row2Col1、Row2Col3、Row2Col4)的表,我想从动态生成的字符串中获取它们的 id。代码是:
String index = "Row" + (currentRow + 2) + "Col1";
Button buttonTable = (Button) findViewById(getResources()
.getIdentifier(index, "id", getPackageName()));
buttonTable.setVisibility(0);
index = "Row" + (currentRow + 2) + "Col3";
TextView textViewBrand = new TextView(getApplicationContext());
textViewBrand = (TextView) findViewById(getResources().getIdentifier(
index, "id", getPackageName()));
textViewBrand.setText(brand);
index = "Row" + (currentRow + 2) + "Col4";
TextView textViewTread = new TextView(getApplicationContext());
textViewTread = (TextView) findViewById(getResources().getIdentifier(
index, "id", getPackageName()));
textViewTread.setText(tread);
程序在第二行崩溃,findViewById 在哪里。有任何想法吗?