活动中的按钮和GridView视图

时间:2013-09-19 20:09:17

标签: java android

public class ScenesActivity extends Activity implements Animation.AnimationListener, View.OnClickListener {
private Button mBack;
private Button mExit;
private Button mAbout;

private GridView gridView;
private GridViewAdapter customGridAdapter;

private int mCurrentAnimationObjectNumber = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
   setContentView(R.layout.scenes_grid);

   initializeClicks();
   gridView = (GridView) findViewById(R.id.gridView);
   customGridAdapter = new GridViewAdapter(this, R.layout.row_grid, getData());
   gridView.setAdapter(customGridAdapter);

   gridView.setOnItemClickListener(new OnItemClickListener() {
   public void onItemClick(AdapterView<?> parent, View v,
   int position, long id) {
   Toast.makeText(ScenesActivity.this, position + "#Selected",
  Toast.LENGTH_SHORT).show();
   }

});

   initializeClicks();
}

private ArrayList<ImageItem> getData() {
   final ArrayList<ImageItem> imageItems = new ArrayList<ImageItem>();
   TypedArray imgs = getResources().obtainTypedArray(R.array.image_ids);
   Bitmap farmAnimals = BitmapFactory.decodeResource(this.getResources(), imgs.getResourceId(0, -1));
   imageItems.add(new ImageItem(farmAnimals, "Farm Animals"));

   Bitmap fruitsVeg = BitmapFactory.decodeResource(this.getResources(), imgs.getResourceId(1, -1));
   imageItems.add(new ImageItem(fruitsVeg, "Fruits & Vegetables"));

   Bitmap childrenRoom = BitmapFactory.decodeResource(this.getResources(), imgs.getResourceId(2, -1));
   imageItems.add(new ImageItem(childrenRoom, "Children Room"));

   Bitmap beach = BitmapFactory.decodeResource(this.getResources(), imgs.getResourceId(3, -1));
   imageItems.add(new ImageItem(beach, "Beach"));

   Bitmap transport = BitmapFactory.decodeResource(this.getResources(), imgs.getResourceId(4, -1));
   imageItems.add(new ImageItem(transport, "transport"));

   return imageItems;
}

private void initializeClicks(){
   mBack = (Button) findViewById(R.id.back);
   mExit = (Button) findViewById(R.id.exit);
   mAbout = (Button) findViewById(R.id.about);
   mBack.setOnClickListener(this);
   mExit.setOnClickListener(this);
   mAbout.setOnClickListener(this);
}

点击ScenesActivity后,流程意外停止。我已经调试了代码,当它尝试在initializeClicks()方法中设置单击侦听器时问题就开始了。我不知道如何解决它。有人可以帮忙解决这个问题吗?

0 个答案:

没有答案