在android studio的TextView字段上打印/显示二维数组(int)的值的代码是什么? 当用户在EditText字段上放置行,列值并单击按钮时,我希望结果出现在TextView上。
public class MainActivity extends AppCompatActivity {
EditText value01, value02;
Button show;
TextView result;
int mpaTable[][] = new int[4][4];
int[][] MpaTable = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
value01 = (EditText)findViewById(R.id.value01);
value02 = (EditText)findViewById(R.id.value02);
show = (Button)findViewById(R.id.button);
result = (TextView)findViewById(R.id.result); }
public void btnClick(View V){
int a = Integer.parseInt(value01.getText().toString());
int b = Integer.parseInt(value02.getText().toString());
result.setText(mpaTable[a][b]);
}
}
答案 0 :(得分:0)
更改此行
result.setText(A + “---” + B);
它适用于你。