ListView,GridView点击事件

1,单击事件

 1  GridView gv_home = (GridView) findViewById(R.id.gv_home);
 2         //获取HomeAdapter对象(自定义的一个BaseAdapter)
 3         HomeAdapter adapter = new HomeAdapter();
 4         gv_home.setAdapter(adapter);
 5       //监听点击
 6         gv_home.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 7             @Override
 8             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //点击后要进行的操作
9 switch (position){ 10 case 0: 11 break; 12 case 8: 13 startActivity(new Intent(HomeActivity.this,SettingActivity.class)); 14 break; 15 } 16 } 17 });

2,长摁事件

1 gv_home.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
2         
3             @Override
4             public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
           //返回true不会触发此事件
5 return false; 6 } 7 });

 

你可能感兴趣的:(ListView,GridView点击事件)