Android:滑动列表项导致clickOnItem
我想左右滑动listview中的项目。 为此,我使用这个项目 我可以滑动项目,但当我在滑动项目后调用项目的onclick。我不要这个。 我在SwipeListener上做了努力,但我没有完全克服这种情况。我可以从左向右滑动而不调用onClickItem,但当我向后滑动Item时,请单击callAndroid:滑动列表项导致clickOnItem,android,listview,swipe,Android,Listview,Swipe,我想左右滑动listview中的项目。 为此,我使用这个项目 我可以滑动项目,但当我在滑动项目后调用项目的onclick。我不要这个。 我在SwipeListener上做了努力,但我没有完全克服这种情况。我可以从左向右滑动而不调用onClickItem,但当我向后滑动Item时,请单击call swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { @Override publ
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onStartOpen(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onOpen(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onStartClose(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onClose(SwipeLayout swipeLayout) {
lineIsClose = true ;
}
@Override
public void onUpdate(SwipeLayout swipeLayout, int i, int i1) {
}
@Override
public void onHandRelease(SwipeLayout swipeLayout, float v, float v1) {
}
});
编辑:一些代码
adapter = new ProductsListAdapter(getActivity(), currentList);
adapter.setMode(Attributes.Mode.Multiple);
listView.setAdapter(adapter);
package com.akakce.market.Adapters;
导入android.content.Context;
导入android.graphics.Color;
导入android.graphics.Paint;
导入android.os.Handler;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ImageView;
导入android.widget.TextView;
导入com.daimajia.swipe.SwipeLayout;
导入com.daimajia.swipe.adapters.BaseSwipeAdapter;
导入com.akakce.market.Models.ProductList;
导入com.akakce.market.Managers.SharedPrefManager;
导入com.akakce.market.Models.Product;
import com.akakce.market.R;
导入com.akakce.market.Utils.GifMovieView;
导入java.util.List;
/**
*由纽约城市大学于2015年7月1日创建。
*/
公共类ProductsListAdapter扩展了BaseSwipeAdapter{
语境;
名单;
产品列表;
布尔lineIsClose=true;
public ProductsListAdapter(上下文上下文,ProductList currentList){
this.mContext=上下文;
this.currentList=currentList;
this.list=currentList.getProducts();
}
@凌驾
公共int getSwipeLayoutResourceId(int i){
返回R.id.swipe;
}
@凌驾
公共视图生成视图(最终整数位置,视图组视图组){
视图v=LayoutFlater.from(mContext)。充气(R.layout.item\u products\u list,空);
返回v;
}
@凌驾
公共无效填充值(最终整型位置,视图转换视图){
产品温度=列表获取(位置);
final TextView name=(TextView)convertView.findViewById(R.id.name);
最终TextView计数=(TextView)convertView.findViewById(R.id.count);
最终ImageView类别视图=(ImageView)convertView.findViewById(R.id.ImageView\u类别);
final GifMovieView GifMovieView=(GifMovieView)convertView.findViewById(R.id.gif_1);
最终SwipeLayout SwipeLayout=(SwipeLayout)convertView.findViewById(getSwipeLayoutResourceId(position));
swipeLayout.getDragEdgeMap().clear();
swipeLayout.addDrag(swipeLayout.DragEdge.Left,swipeLayout.findViewById(R.id.bottom_包装器));
swipeLayout.addSwipeListener(新的swipeLayout.SwipeListener(){
@凌驾
开始开放时的公共空间(SwipeLayout SwipeLayout){
lineIsClose=false;
}
@凌驾
公共空间开放(SwipeLayout SwipeLayout){
lineIsClose=false;
}
@凌驾
开始关闭时的公共无效(SwipeLayout SwipeLayout){
lineIsClose=false;
}
@凌驾
公共排水沟(SwipeLayout SwipeLayout){
lineIsClose=true;
}
@凌驾
公共空间更新(SwipeLayout SwipeLayout,int i,int i1){
}
@凌驾
手动释放时的公共无效(SwipeLayout SwipeLayout、浮动v、浮动v1){
}
});
如果(临时完成()){
name.setTextColor(mContext.getResources().getColor(R.color.gray));
name.setPaintFlags(name.getPaintFlags()| Paint.STRIKE_-THRU_-TEXT_-FLAG);
count.setPaintFlags(count.getPaintFlags()| Paint.STRIKE_-THRU_-TEXT_-FLAG);
}否则{
name.setTextColor(mContext.getResources().getColor(R.color.black));
name.setPaintFlags(name.getPaintFlags()&(~Paint.STRIKE_-THRU_-TEXT_-FLAG));
count.setPaintFlags(count.getPaintFlags()&(~Paint.STRIKE_-THRU_-TEXT_-FLAG));
}
name.setText(temp.getName());
count.setText(“+temp.getCount());
if(位置%2==0)//oylesine变量
categoryView.setBackgroundColor(颜色:蓝色);
如果(位置%3==0)
categoryView.setBackgroundColor(颜色:红色);
convertView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(lineIsClose){
gifMovieView.setVisibility(View.VISIBLE);
最终处理程序=新处理程序();
handler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
gifMovieView.setVisibility(View.GONE);
如果(!list.get(position).isCompleted()){//false-ise-true-yap
list.get(position).setCompleted(true);
name.setTextColor(mContext.getResources().getColor(R.color.gray));
name.setPaintFlags(name.getPaintFlags()| Paint.STRIKE_-THRU_-TEXT_-FLAG);
count.setPaintFlags(count.getPaintFlags()| Paint.STRIKE_-THRU_-TEXT_-FLAG);
}否则{//true-ise-false-yap
list.get(position).setCompleted(false);
name.setTextColor(mContext.getResources().getColor(R.color.black));
name.setPaintFlags(name.getPaintFlags()&(~Paint.STRIKE_-THRU_-TEXT_-FLAG));
count.setPaintFlags(count.getPaintFlags()&(~Paint.STRIKE_-THRU_-TEXT_-FLAG));
}
currentList.setProducts(列表);
SharedPrefManager.saveList(当前列表);
}
}, 600);
//保存列表(gifMovieView);
}
}
});
convertView.findViewById(R.id.bottom_包装器).setOnClickListener(新视图.OnClickListener(){
@凌驾
package com.akakce.market.Adapters;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.daimajia.swipe.SwipeLayout;
import com.daimajia.swipe.adapters.BaseSwipeAdapter;
import com.akakce.market.Models.ProductList;
import com.akakce.market.Managers.SharedPrefManager;
import com.akakce.market.Models.Product;
import com.akakce.market.R;
import com.akakce.market.Utils.GifMovieView;
import java.util.List;
/**
* Created by cuneyt on 1.7.2015.
*/
public class ProductsListAdapter extends BaseSwipeAdapter {
Context mContext;
List<Product> list;
ProductList currentList;
boolean lineIsClose = true;
public ProductsListAdapter(Context context, ProductList currentList) {
this.mContext = context;
this.currentList = currentList;
this.list = currentList.getProducts();
}
@Override
public int getSwipeLayoutResourceId(int i) {
return R.id.swipe;
}
@Override
public View generateView(final int position, ViewGroup viewGroup) {
View v = LayoutInflater.from(mContext).inflate(R.layout.item_products_list, null);
return v;
}
@Override
public void fillValues(final int position, View convertView) {
Product temp = list.get(position);
final TextView name = (TextView) convertView.findViewById(R.id.name);
final TextView count = (TextView) convertView.findViewById(R.id.count);
final ImageView categoryView = (ImageView) convertView.findViewById(R.id.imageView_category);
final GifMovieView gifMovieView = (GifMovieView) convertView.findViewById(R.id.gif_1);
final SwipeLayout swipeLayout = (SwipeLayout) convertView.findViewById(getSwipeLayoutResourceId(position));
swipeLayout.getDragEdgeMap().clear();
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, swipeLayout.findViewById(R.id.bottom_wrapper));
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onStartOpen(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onOpen(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onStartClose(SwipeLayout swipeLayout) {
lineIsClose = false;
}
@Override
public void onClose(SwipeLayout swipeLayout) {
lineIsClose = true ;
}
@Override
public void onUpdate(SwipeLayout swipeLayout, int i, int i1) {
}
@Override
public void onHandRelease(SwipeLayout swipeLayout, float v, float v1) {
}
});
if (temp.isCompleted()) {
name.setTextColor(mContext.getResources().getColor(R.color.gray));
name.setPaintFlags(name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
count.setPaintFlags(count.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
name.setTextColor(mContext.getResources().getColor(R.color.black));
name.setPaintFlags(name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
count.setPaintFlags(count.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
name.setText(temp.getName());
count.setText("" + temp.getCount());
if (position % 2 == 0)// oylesine var
categoryView.setBackgroundColor(Color.BLUE);
if (position % 3 == 0)
categoryView.setBackgroundColor(Color.RED);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ( lineIsClose ){
gifMovieView.setVisibility(View.VISIBLE);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
gifMovieView.setVisibility(View.GONE);
if (!list.get(position).isCompleted()) {//false ise true yap
list.get(position).setCompleted(true);
name.setTextColor(mContext.getResources().getColor(R.color.gray));
name.setPaintFlags(name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
count.setPaintFlags(count.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else { // true ise false yap
list.get(position).setCompleted(false);
name.setTextColor(mContext.getResources().getColor(R.color.black));
name.setPaintFlags(name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
count.setPaintFlags(count.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
currentList.setProducts(list);
SharedPrefManager.saveList(currentList);
}
}, 600);
//saveList(gifMovieView);
}
}
});
convertView.findViewById(R.id.bottom_wrapper).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
swipeLayout.close();
//
// removeFromList(position);
list.remove(position);
notifyDataSetChanged();
}
});
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
viewHolder.swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, " onClick : " + item.getName() + " \n" + item.getEmailId(), Toast.LENGTH_SHORT).show();
}
});
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
@Override
public void onOpen(SwipeLayout layout) {
super.onOpen(layout);
((Fragment)mFragment).setListViewClickable(false);
}
@Override
public void onClose(SwipeLayout layout) {
super.onClose(layout);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
((Fragment) mFragment).setListViewClickable(true);
}
} , 100);
}
@Override
public void onStartOpen(SwipeLayout layout) {
((Fragment)mFragment).setListViewClickable(false);
super.onStartOpen(layout);
}
@Override
public void onStartClose(SwipeLayout layout) {
((Fragment)mFragment).setListViewClickable(false);
super.onStartClose(layout);
}
});
swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// delete view or something you want to do
}
});