关闭

ListView的item的点击事件和长按事件

3988人阅读 评论(0) 收藏 举报
 mAdapter = new MyCollectAdapter(this, myCollects,mImageLoad.getImageLoadingListener(), mImageLoad.getOptions());
    	  mPullRefreshListView.setAdapter(mAdapter);
    	  
    	  ListView actualListView = mPullRefreshListView.getRefreshableView();
    	  
    	  actualListView.setOnItemClickListener(new OnItemClickListener() {

  			@Override
  			public void onItemClick(AdapterView<?> parent, View view,
  					int position, long id) {
  				MyCollect myCollect = myCollects.get(position - 1);
  				Intent intent = new Intent(MyCollectActivity.this, FindOrderDetailsActivity.class);
  				intent.putExtra("quotation.id", myCollect.id);
  				startActivity(intent);
  			}
  		});
    	  
    	  actualListView.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					final int arg2, long arg3) {
				
				AlertDialog.Builder builder = new AlertDialog.Builder(MyCollectActivity.this);
				
				builder.setMessage("确认删除吗");
				builder.setTitle("提示");
				builder.setNegativeButton("取消", new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						arg0.dismiss();
					}
				});
				builder.setPositiveButton("确定", new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface arg0, int arg1) {
						// TODO Auto-generated method stub
						
						if (myCollects.size() > 0) {
							push(myCollects.get(arg2 - 1).id, arg2);      
						}
						mAdapter.notifyDataSetChanged();
						arg0.dismiss();
					}
				});
				builder.create().show();
				<strong><span style="color:#cc0000;">return true;     // 这里一定要改为true,代表长按自己消费掉了,若为false,触发长按事件的同时,还会触发点击事件</span></strong>
			}
		});

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:111342次
    • 积分:3146
    • 等级:
    • 排名:第11585名
    • 原创:211篇
    • 转载:9篇
    • 译文:0篇
    • 评论:16条
    最新评论