单击按钮时,我需要将数据添加到 gridview 表中。我的代码:
String[] data = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"};
GridView gvMain;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smena);
adapter = new ArrayAdapter<String>(this, R.layout.item, R.id.tvText, data);
gvMain = (GridView) findViewById(R.id.gridView1);
gvMain.setAdapter(adapter);
Button but1=(Button) findViewById(R.id.button1);
but1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
ButtonOn (1);
}
});
}
public void ButtonOn (int Art){
adapter.add("1");
gvMain.setAdapter(adapter);
}
当我单击按钮时,我的应用程序意外停止。