<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/noInterest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f00"
android:text="不感兴趣"/>
</LinearLayout>
shan3 = (ImageView) convertView.findViewById(R.id.imageshan);
LayoutInflater inflater = LayoutInflater.from(context);
// 引入窗口配置文件
View view = inflater.inflate(R.layout.popupwindow, null);
// 创建PopupWindow对象
final PopupWindow pop = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, false);
// 需要设置一下此参数,点击外边可消失
pop.setBackgroundDrawable(new BitmapDrawable());
//设置点击窗口外边窗口消失
pop.setOutsideTouchable(true);
// 设置此参数获得焦点,否则无法点击
pop.setFocusable(true);
shan3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(pop.isShowing()) {
// 隐藏窗口,如果设置了点击窗口外小时即不需要此方式隐藏
pop.dismiss();
} else {
// 显示窗口
pop.showAsDropDown(view);
}
}
});
Button btn = (Button) view.findViewById(R.id.noInterest);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
list.remove(position);
notifyDataSetChanged();
}
});