我创建了一个不使用Adapter的网格视图。我想访问网格视图的单个元素。我该怎么做。我使用以下方式创建网格并将值插入单个网格查看它。请帮助我怎么能这样做......
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one=(TextView)findViewById(R.id.one);
two=(TextView)findViewById(R.id.two);
three=(TextView)findViewById(R.id.three);
btn_check=(Button)findViewById(R.id.btn_check);
btn_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkSubmit();
}
});
mGrid = (GridLayout) findViewById(R.id.grid_layout);
// mGrid.setOnDragListener(new DragListener());
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info = one.getText().toString();
System.out.println("click item===="+info);
System.out.println("position of 1"+pos);
/* TextView textView = (TextView) itemView
.findViewById(R.id.grid_item_label);
textView.setText(textViewValues[position]);*/
}
});
two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info = two.getText().toString();
}
});
three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
info = three.getText().toString();
}
});
inflater = LayoutInflater.from(this);
for (int i = 0; i < NBR_ITEMS; i++) {
final View itemView = inflater.inflate(R.layout.item_grid, mGrid, false);
final TextView text = (TextView) itemView.findViewById(R.id.text);
// String values=text.getText().toString();
// System.out.println("value at 0=="+values);
System.out.println("child at position====");
if ((i == 4)) {
itemView.setEnabled(false);
itemView.setBackgroundColor(Color.parseColor("#999999"));
text.setText("3");
System.out.println("vbdkvjubys"+text);
text.setPadding(60,30,10,10);
}
if ((i == 3)) {
itemView.setEnabled(false);
itemView.setBackgroundColor(Color.parseColor("#999999"));
text.setText("1");
text.setPadding(60,30,10,10);
// text.setClickable(false);
}
if ((i == 7)) {
itemView.setEnabled(false);
itemView.setBackgroundColor(Color.parseColor("#999999"));
text.setText("2");
text.setPadding(60,30,10,10);
}
final int size = mGrid.getChildCount();
System.out.println("size===" + size);
final int finalI = i;
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemView.setBackgroundColor(Color.parseColor("#00ced1"));
itemView.setTag(new Integer(finalI));
Integer position = (Integer)view.getTag();
itemView.setTag(Integer.valueOf(position));
clickedPosition=position;
text.setText(info);
text.setPadding(60,30,10,10);
info="";
System.out.println("position clicked==="+clickedPosition);
System.out.println("click on cell");
}
});
itemView.setBackgroundColor(Color.parseColor("#ffffff"));
// info.replace(info,"");
// itemView.setOnLongClickListener(new LongPressListener());
mGrid.getChildAt(4);
System.out.println("chld value at position=="+ mGrid.getChildAt(4));
mGrid.addView(itemView);
}
}