我在事件处理方面有一些小问题,我具有列表视图自定义适配器数据,每行都有日期,标题和价格.当我单击行时,我需要显示详细信息页面,但是当我长按价格,日期或标题时,我需要对列表视图进行排序.我需要在长按上使用手势.请参考下面的代码,我已经尝试过.
自定义适配器视图
public EventAdapterVIEw(Context context, List<EventUtil> eventList) { this.mContext = context; this.mEventUtil = eventList; mLayoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader = new DrawableManager(); } @Suppresslint("DefaultLocale") @SuppressWarnings("deprecation") @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { mVIEw = convertVIEw; EventUtil eventUtil = mEventUtil.get(position); mVIEw = mLayoutInflater.inflate(R.layout.row_event_adapter, null); TextVIEw eventTitleVIEw = (TextVIEw) mVIEw .findVIEwByID(R.ID.List_vIEw_event_Title); TextVIEw eventDescVIEw = (TextVIEw) mVIEw .findVIEwByID(R.ID.List_vIEw_event_location); TextVIEw eventDateVIEw = (TextVIEw) mVIEw .findVIEwByID(R.ID.List_vIEw_event_price); // final MyGestureDetector myGestureDetector= new MyGestureDetector(); // new ImageFeach().execute(mEventUtil.getEvent_Image_Url()); eventTitleVIEw.setText(eventUtil.getEvent_Title()); // event Title sorting eventTitleVIEw.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { new MyGestureDetector() { public voID onLongPress(MotionEvent event1) { //if (event1.getAction() == MotionEvent.ACTION_DOWN) { Collections.sort(mEventUtil, new Comparator<EventUtil>() { @OverrIDe public int compare(EventUtil obje1, EventUtil obje2) { return obje1 .getEvent_Title() .compareto( obje2.getEvent_Title()); } }); notifyDataSetChanged(); //} }; }.onLongPress(event); return true; } }); // event location sorting eventDescVIEw.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { new MyGestureDetector() { public voID onLongPress(MotionEvent event1) { //if (event1.getAction() == MotionEvent.ACTION_DOWN) { Collections.sort(mEventUtil, new Comparator<EventUtil>() { @OverrIDe public int compare(EventUtil event1, EventUtil event2) { return event1 .getEvent_location() .compareto( event2.getEvent_location()); } }); notifyDataSetChanged(); //} }; }.onLongPress(event); return true; } }); // event price sorting eventDateVIEw.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { new MyGestureDetector() { public voID onLongPress(MotionEvent event1) { // if (event1.getAction() == MotionEvent.ACTION_DOWN) { Collections.sort(mEventUtil, new Comparator<EventUtil>() { @OverrIDe public int compare(EventUtil event1, EventUtil event2) { return event1 .getEvent_Price() .compareto( event2.getEvent_Price()); } }); notifyDataSetChanged(); //} }; }.onLongPress(event); return true; } }); // event date sorting ImageVIEw dateImageVIEw = (ImageVIEw) mVIEw .findVIEwByID(R.ID.List_vIEw_event_date); dateImageVIEw.setontouchListener(new OntouchListener() { @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { new MyGestureDetector() { public voID onLongPress(MotionEvent event1) { //if (event1.getAction() == MotionEvent.ACTION_DOWN) { Collections.sort(mEventUtil, new Comparator<EventUtil>() { @OverrIDe public int compare(EventUtil event1, EventUtil event2) { return event2 .getEvent_Date() .compareto( event1.getEvent_Date()); } }); notifyDataSetChanged(); //} }; }.onLongPress(event); return true; } });
MyGestureDetector类
public class MyGestureDetector extends SimpleOnGestureListener { @OverrIDe public voID onLongPress(MotionEvent e) { super.onLongPress(e); }}
帮帮我..谢谢
解决方法:
我认为,无需使用SimpleOnGestureListener.
在您的自定义适配器视图中:
第一,
eventTitleVIEw.setFocusable(false); eventTitleVIEw.setFocusableIntouchMode(false);eventTitleVIEw.setLongClickable(true);eventDescVIEw.setFocusable(false); eventDescVIEw.setFocusableIntouchMode(false);eventDescVIEw.setLongClickable(true);eventDateVIEw.setFocusable(false); eventDateVIEw.setFocusableIntouchMode(false);eventDateVIEw.setLongClickable(true);
然后,
只需将eventTitleVIEw,eventDescVIEw和eventDateVIEw的setonLongClickListener(VIEw.OnLongClickListener l)设置为
eventTitleVIEw.setonItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) { //do your sorting stuff here } });eventDescVIEw.setonItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) { //do your sorting stuff here } });eventDateVIEw.setonItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) { //do your sorting stuff here } });
希望这对您有所帮助.
总结以上是内存溢出为你收集整理的android-如何处理ListView项目LongPress手势全部内容,希望文章能够帮你解决android-如何处理ListView项目LongPress手势所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)