我想从字符串的二维数组创建表。不过,我吸引用代码创建视图,所以出于某种原因,我的图像永远不可见,并且我的文本视图不会分成多行,而是剔除文本。在android中创建动态表
此外,我在代码中的每个文本视图上放置了id,当有人单击textview时,我希望能够使用该ID来识别被点击的whick行。不幸的是,情况并非如此。
有没有什么好的方法来识别正确的行?
问候
for (int current=0; current<cityArr.length; current++) {
TableRow tr = new TableRow(this);
tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView labelTV = new TextView(this);
labelTV.setId(current);
labelTV.setText(cityArr[current][0]);
labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
ImageView mapView = new ImageView(this);
mapView.setImageResource(R.drawable.list_icon_map);
mapView.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, 5));
tr.addView(mapView);
tlcity.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}