onitemclicklistene里怎么获取当前item
答案:2 悬赏:30 手机版
解决时间 2021-04-04 16:20
- 提问者网友:像風在裏
- 2021-04-03 16:16
onitemclicklistene里怎么获取当前item
最佳答案
- 五星知识达人网友:思契十里
- 2021-04-03 17:38
以 bookshelf 为例 ,为其设置适配器 adapter,设置点击事键,在class ShlefAdapter 中的getItem方法中得到 item值
bookShelf = (GridView) findViewById (R.id.bookShelf);
ShlefAdapter adapter=new ShlefAdapter();
bookShelf.setAdapter(adapter);
bookShelf.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, final View arg1, final int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
class ShlefAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.length+1;
}
@Override
public Object getItem(int arg0) { //得到所点击的Item的值。
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int position, View contentView, ViewGroup arg2) {
// TODO Auto-generated method stub
//动态载入item
contentView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.item1, null);
TextView view=(TextView) contentView.findViewById(R.id.imageView1);
return contentView;
}
}
bookShelf = (GridView) findViewById (R.id.bookShelf);
ShlefAdapter adapter=new ShlefAdapter();
bookShelf.setAdapter(adapter);
bookShelf.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, final View arg1, final int arg2, long arg3) {
// TODO Auto-generated method stub
}
});
class ShlefAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.length+1;
}
@Override
public Object getItem(int arg0) { //得到所点击的Item的值。
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int position, View contentView, ViewGroup arg2) {
// TODO Auto-generated method stub
//动态载入item
contentView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.item1, null);
TextView view=(TextView) contentView.findViewById(R.id.imageView1);
return contentView;
}
}
全部回答
- 1楼网友:轮獄道
- 2021-04-03 18:08
你说呢...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯