查找了网上很多文章,说是在XML文件设置textview的focus为false ,简直是一派胡言,那样连文本都输入不了了,有何用
网上查找无果,改用java代码控制listview的longclick方法,实现弹出复制和删除listview的办法
自定义一个popWindow
private void initPopupWindow(LayoutInflater inflater) {
View view = inflater.inflate(R.layout.pop_item_layout, null);
popupWindow = new PopupWindow(view, 100, 50);
// popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
// popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
copyTv = (TextView) view.findViewById(R.id.pop_copy_tv);
deleteTv = (TextView) view.findViewById(R.id.pop_delete_tv);
}
然后自己写一个监听方法
class tvOnTouch implements OnTouchListener {
private Context mContext;
private int mPosition;
public tvOnTouch(Context context, int position) {
// TODO Auto-generated method stub
this.mContext = context;
this.mPosition = position;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (v.getId() == R.id.pop_copy_tv) {
TextView tv = (TextView) v;
if (event.getAction() == MotionEvent.ACTION_DOWN) {// 按下
tv.setTextColor(0xff00CD66);
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 弹起
tv.setTextColor(0xffffffff);
com.robot.utils.TextManager.copyText(mContext, mDatas.get(mPosition).getMsg());
Toast.makeText(mContext, "复制成功", SHOW_TIME).show();
if (popupWindow != null) {
popupWindow.dismiss();
}
}
} else {
TextView tv = (TextView) v;
if (event.getAction() == MotionEvent.ACTION_DOWN) {// 按下
tv.setTextColor(0xff00CD66);
} else if (event.getAction() == MotionEvent.ACTION_UP) {// 谈起
tv.setTextColor(0xffffffff);
mDatas.remove(mPosition);
notifyDataSetChanged();
Toast.makeText(mContext, "删除成功", SHOW_TIME).show();
if (popupWindow != null) {
popupWindow.dismiss();
}
}
}
return true;
}
}
最后在getview里加入监听事件
viewHolder.content.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
showPop(v);
copyTv.setOnTouchListener(new tvOnTouch(mContext, position));
deleteTv.setOnTouchListener(new tvOnTouch(mContext, position));
return false;
}
});