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

 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();
				return true;     // 这里一定要改为true,代表长按自己消费掉了,若为false,触发长按事件的同时,还会触发点击事件
			}
		});

你可能感兴趣的:(ListView的item的点击事件和长按事件)