【安卓】Listview里面Headerview的问题
Listview添加了Headerview,Headerview里面有一个Gridview显示图片,结果Gridview图片无法响应点击事件?!
LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);View Header=inflater.inflate(R.layout.card_view_detail,null);
mListView.addHeaderView(Header);
mListView.setAdapter(null);
final MyGridView de_images1=(MyGridView)Header.findViewById(R.id.de_images1);
//判断微博中是否有图片
if (!StringUtil.isEmpty(list.thumbnail_pic)){
final ArrayList<String> list2=list.pic_urls;
de_r14.setVisibility(View.VISIBLE);
//九宫格显示图片
int w=0;
int wh=(SysUtils.getScreenWidth(WeiboDetail.this)- SysUtils.Dp2Px(WeiboDetail.this, 99))/3;
switch (list2.size()){
case 1:
w=wh;
de_images1.setNumColumns(1);
break;
case 2:
case 4:
w=2*wh+ SysUtils.Dp2Px(WeiboDetail.this, 2);
de_images1.setNumColumns(2);
break;
case 3:
case 5:
case 6:
w=wh*3+SysUtils.Dp2Px(WeiboDetail.this, 2)*2;
de_images1.setNumColumns(3);
break;
case 7:
case 8:
case 9:
w=wh*3+SysUtils.Dp2Px(WeiboDetail.this, 2)*2;
de_images1.setNumColumns(3);
break;
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(w, RelativeLayout.LayoutParams.WRAP_CONTENT);
de_images1.setLayoutParams(lp);
GridViewAdapter nearByInfoImgsAdapter = new GridViewAdapter(WeiboDetail.this, list2);
de_images1.setAdapter(nearByInfoImgsAdapter);
//点击事件,点击没反应
de_images1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
Intent intent = new Intent(WeiboDetail.this, ImagePagerActivity.class);
intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, Tools.getOriginalPicUrls(list2));
intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, arg2);
startActivity(intent);
}
});
}else {
de_r14.setVisibility(View.GONE);
}
回答
你代码都没有,只能说一般套路绑定该控件实现监听事件
"Headerview里面只有Gridview的Item无法触发click事件,其他的Button都是可以触发click事件的".
把上述Button改成TextView试试。
以上是 【安卓】Listview里面Headerview的问题 的全部内容, 来源链接: utcz.com/a/104155.html