我有 10 个线性布局如何识别每个线性布局,所以我需要对它执行一些操作
下面是代码
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
newsLayout =(LinearLayout)findViewById(R.id.newsLayout);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rel=null;
for(int i=0;i<images.size();i++){
rel= new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel.setId(i);
rel = (RelativeLayout) inflater.inflate(R.layout.reuse,null);
params.setMargins(0, 50, 0, 0);
TextView fromWeb= (TextView) rel.findViewById(R.id.text);
fromWeb.setText(headLines.get(i));
newsLayout.addView(rel,params);
rel.setOnClickListener(new RelativeLayout.OnClickListener() {
public void onClick(View arg0) {
switch(arg0.getId()) {
case 1: Toast.makeText(DesignShape.this, "clicked"+arg0.getId(), Toast.LENGTH_LONG).show();
break;
default: break;
}
}
});
}
}
线性布局上的点击事件每次都会产生相同的对象。我怎样才能彼此区分