我是Android编程新手。这个问题可能很容易,但我无法得到一个解决方案。 我想设置一个空的gridview并设置一个从1开始的数字,并在点击gridview的任何项目时增加。 我可以设置gridview但无法将数字设置为单击的项目。有人可以帮忙吗?谢谢... 这是代码;
公共类MainActivity扩展了Activity {
GridView grid;
String[] numbers = new String[] { "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
grid = (GridView) findViewById(R.id.gridview);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1,numbers);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
numbers[position]="1";
}
});
}