获取表行Android中的视图

时间:2014-01-17 10:06:03

标签: android

for (int i = 0; i < listData.size(); i++) {         
 final TableRow tr = new TableRow(referenceActivity);
 tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                                       LayoutParams.MATCH_PARENT));
 LayoutInflater inflater1 = (LayoutInflater) referenceActivity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 View rowData = inflater1.inflate(R.layout.categoryadapter, null);
 final ImageView lPic = (ImageView) rowData.findViewById(R.id.imageView1);
 final ImageView rPic = (ImageView) rowData.findViewById(R.id.imageView2);
 TextView category = (TextView) rowData.findViewById(R.id.textView_category);
 tr.addView(rowData);
 tv.addView(tr);            
}

如果我点击一行,我想更改ImageView中的图像。所以我想在行中获得所有三个视图(两个ImageView和一个TextView)。             我怎样才能获得意见?

1 个答案:

答案 0 :(得分:1)

创建一个id给你TableRow,同时创建所需的每个地方。只需使用以下代码即可获得。{/ p>

TableRow tr = findViewById(yourId);

并获取您的imageView

ImageView iv =(ImageView ) tr.getChildAt(0); // 0 is imageView position in tableRow 
                                             // change that with your need

如果您直接添加View,可以尝试:

   ImageView iv = tr.findViewById(R.id.imageID);