pop的实际应用
来源:互联网 发布:网络包年维护服务 编辑:程序博客网 时间:2024/05/17 06:57
主页面
ListView lv = (ListView) findViewById(R.id.main_lv);list = new ArrayList<>();for (int i = 0; i < 20; i++) { list.add("这是第" + i + "条");}lv.setAdapter(new MyAdapter(MainActivity.this,list));
适配器
public class MyAdapter extends BaseAdapter { private LayoutInflater Inflater; private ArrayList<String> list; private TextView tv; private Context context; private ImageView img; private PopupWindow window; private TextView tv1; private TextView tv2; public MyAdapter(Context context, ArrayList<String> list) { Inflater = LayoutInflater.from(context); this.context = context; this.list = list; initPopView(); } @Override public int getCount() { return list.size(); } @Override public Object getItem(int i) { return list.get(i); } @Override public long getItemId(int i) { return i; } @Override public View getView(final int i, View view, ViewGroup viewGroup) { view = View.inflate(context, R.layout.item, null); tv = view.findViewById(R.id.item_tv); img = view.findViewById(R.id.item_img); tv.setText(list.get(i)); img.setOnClickListener(new PopWindow(i)); return view; } class PopWindow implements View.OnClickListener { private int position; public PopWindow(int position) { this.position = position; }//显示在当前item上 @Override public void onClick(View view) { int[] ints = new int[2]; view.getLocationInWindow(ints); int x = ints[0]; int y = ints[1]; showPop(view, position, x, y); } } private void initPopView() { View view = Inflater.inflate(R.layout.poupwindow_layout, null); window = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //必须写,不写的话,点击popwindow外面没有效果 window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000"))); // window.setAnimationStyle(R.style.popWindowAnimation); //知道popwindow中间的控件 ,去做点击 tv1 = view.findViewById(R.id.t1); tv2 = view.findViewById(R.id.t2); } private void showPop(View parent, final int position, int x, int y) { //根据view的位置显示popupwindow的位置 window.showAtLocation(parent, 0, x, y); //根据view的位置popupwindow将显示到他的下面 , 可以通过x ,y 参数修正这个位置 // mPopupWindow.showAsDropDown(parent,0,-50); //设置popupwindow可以获取焦点,不获取焦点的话 popupwiondow点击无效 window.setFocusable(true); //点击popupwindow的外部,popupwindow消失 window.setOutsideTouchable(true); tv2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { list.remove(position); notifyDataSetChanged(); if (window.isShowing()) { window.dismiss(); } } }); tv1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (window.isShowing()) { window.dismiss(); } } });}}
item的控件
<TextView android:textSize="25sp" android:layout_marginTop="15dp" android:id="@+id/item_tv" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /><ImageView android:id="@+id/item_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" />
popupwindow的控件
<TextView android:id="@+id/t1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="读文章" android:textSize="30sp" /> <TextView android:id="@+id/t2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="不感兴趣" android:textSize="30sp" />
阅读全文
0 0
- pop的实际应用
- SOA 的实际应用
- Filter的实际应用
- 反射的实际应用
- 门禁的实际应用
- CLHLock的实际应用
- MV5的实际应用
- ROW_NUMBER() 的实际应用
- ArrayList的实际应用
- AOP的实际应用
- HashMap的实际应用
- AS2的实际应用
- 多线程的实际应用
- 设计模式的实际应用
- 几个推广的实际应用
- 排序算法的实际应用
- c语言的实际应用?
- Mahout的实际应用(一)
- Android源码修改所了解的默认语言及默认时区对应表
- caffe基础-13AlexNet模型bvlc_reference_caffenet的测试
- Theano dimshuffle函数用法
- 第四周项目(2)-建立链表的算法库
- 扫地僧身份解析
- pop的实际应用
- oracle之触发器(trigger)
- VIM 移动
- plink做SNP筛选和GWAS
- JS中的!=、== 、!==、===的用法和区别
- 剑指offer 最小的k个数
- 阿里云文件迁移工具
- Demo015_异或进行加密
- 彩色图像变换为灰度图像