说下重点吧。先导入这个第三方
然后在item 的点击事件 添加代码
QPopuWindow.getInstance(ListViewActivity.this).builder .bindView(view, position) .setPopupItemList(new String[]{"复制", "粘贴", "转发", "更多...."}) .setPointers(rawX, rawY) .setOnPopuListItemClickListener(new QPopuWindow.OnPopuListItemClickListener() { /** * @param anchorView 为pop的绑定view * @param anchorViewPosition pop绑定view在ListView的position * @param position pop点击item的position 第一个位置索引为0 */ @Override public void onPopuListItemClick(View anchorView, int anchorViewPosition, int position) { Toast.makeText(ListViewActivity.this, anchorViewPosition + "---->" + position, Toast.LENGTH_SHORT).show(); } }).show();
至于这个anchorViewPosition + "---->" + position 得给自己长个记性
switch (position) {//anchorViewPosition 每一条的数。 case 0: showRename(anchorViewPosition);//重命名 break; case 1: getDeleteDialog(anchorViewPosition);//删除 break; case 2: if (AppNetworkMgr.isNetworkConnected(MainActivity.this)) { Log.e("连接", "连接"); //发送 Recorder recorder = mDates.get(anchorViewPosition); String enter_str = filePath + recorder.getFileName() + "_" + recorder.getFileTime() + ".wav";//旧文件 CopyUtils.copyFile(enter_str, Environment.getExternalStorageDirectory() + "/xxxxx/" + recorder.getFileName() + ".wav"); Intent share = new Intent(Intent.ACTION_SEND); //创建组件 ComponentName component = new ComponentName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity"); share.setComponent(component); //设置组件 share.putExtra(Intent.EXTRA_STREAM, (FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName() + ".provider", new File(Environment.getExternalStorageDirectory() + "/果乐录音ZIP/" + recorder.getFileName() + ".wav")))); share.setType("*/*"); startActivity(Intent.createChooser(share, "分享到")); } else { Log.e("不连接", "不连接"); Toast.makeText(MainActivity.this, "网络未连接", Toast.LENGTH_SHORT).show(); } break;
希望能帮助到大家。一同奋进吧!!!