Skip to content

can't disable item in list view #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lazypixelIn opened this issue Sep 5, 2014 · 8 comments
Closed

can't disable item in list view #19

lazypixelIn opened this issue Sep 5, 2014 · 8 comments
Labels

Comments

@lazypixelIn
Copy link

First of all awesome library man..
But there is only one problem i am facing i cant disable any listview item..
i try using is enable override mathod of adpter but still item is enabled..
please answer asap....

@daimajia
Copy link
Owner

daimajia commented Sep 6, 2014

Hey, thanks your feedback. Could you please paste your code here? Which method you are using to disable item?

@lazypixelIn
Copy link
Author

This is My whole adapter code...
for testing purpose i directly use false in is enable method..
private class MyAdapter extends SwipeAdapter {

    Context mContext;
    ImageLoader imgLoader;

    public MyAdapter(Context mContext, List<LocationModel> cat) {

        this.mContext = mContext;
        imgLoader = new ImageLoader(mContext);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public void fillValues(int position, View view) {

        try {
            TextView t1;
            ImageView i1;
            LocationModel c = list.get(position);

            t1 = (TextView) view.findViewById(R.id.textView1);
            i1 = (ImageView) view.findViewById(R.id.imageView1);

            t1.setText(c.getAddress());
            String latEiffelTower = c.getLat() + "";
            String lngEiffelTower = c.getLog() + "";
            String url = "http://maps.google.com/maps/api/staticmap?zoom=15&markers="
                    + latEiffelTower
                    + ","
                    + lngEiffelTower
                    + "&size=200x200&sensor=false";
            imgLoader.DisplayImage(url, i1);
        } catch (Exception e) {
            Log.e("111", e.toString());
        }
    }

    @Override
    public View generateView(final int position, ViewGroup arg1) {
        View v = LayoutInflater.from(mContext).inflate(
                R.layout.row_location, null);
        SwipeLayout swipeLayout = (SwipeLayout) v
                .findViewById(getSwipeLayoutResourceId(position));
        swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {

            @Override
            public void onUpdate(SwipeLayout arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onOpen(SwipeLayout layout) {

                Button add, edit, delete;
                edit = (Button) layout.findViewById(R.id.edit);
                add = (Button) layout.findViewById(R.id.add);
                delete = (Button) layout.findViewById(R.id.remove);
                edit.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((MainActivity) getActivity()).addlocation(1,
                                list.get(position));

                    }
                });
                add.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((MainActivity) getActivity()).addlocation(0);

                    }
                });
                delete.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        db.removelocation(list.get(position).getL_id());
                        list.remove(position);
                        notifyDataSetChanged();
                    }
                });
            }

            @Override
            public void onHandRelease(SwipeLayout arg0, float arg1,
                    float arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onClose(SwipeLayout layout) {

            }
        });

        return v;
    }

    @Override
    public boolean isEnabled(int position) {
        if (list.get(position).isIsservisable() == 1) {
            return false;
        } else {
            return false;
        }
    }

    @Override
    public int getSwipeLayoutResourceId(int arg0) {

        return R.id.swipe;
    }
} 

@daimajia
Copy link
Owner

daimajia commented Sep 6, 2014

Hi, please bind listener in fillValue method rather than in generateView, have a try.

@daimajia
Copy link
Owner

daimajia commented Sep 6, 2014

move the following code to fillValues reasons here: https://github.com/daimajia/AndroidSwipeLayout/wiki/SwipeAdapter#example

        swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {

            @Override
            public void onUpdate(SwipeLayout arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onOpen(SwipeLayout layout) {

                Button add, edit, delete;
                edit = (Button) layout.findViewById(R.id.edit);
                add = (Button) layout.findViewById(R.id.add);
                delete = (Button) layout.findViewById(R.id.remove);
                edit.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((MainActivity) getActivity()).addlocation(1,
                                list.get(position));

                    }
                });
                add.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((MainActivity) getActivity()).addlocation(0);

                    }
                });
                delete.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        db.removelocation(list.get(position).getL_id());
                        list.remove(position);
                        notifyDataSetChanged();
                    }
                });
            }

            @Override
            public void onHandRelease(SwipeLayout arg0, float arg1,
                    float arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onClose(SwipeLayout layout) {

            }
        });

@daimajia
Copy link
Owner

daimajia commented Sep 6, 2014

BTW. you can use SimpleSwipeListener to make your code clean.

@lazypixelIn
Copy link
Author

i done as you told me but there list rows are still enable...here's my new code

private class MyAdapter extends SwipeAdapter {

    Context mContext;
    ImageLoader imgLoader;

    public MyAdapter(Context mContext, List<LocationModel> cat) {

        this.mContext = mContext;
        imgLoader = new ImageLoader(mContext);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public void fillValues(final int position, View view) {

        try {
            TextView t1;
            ImageView i1;
            LocationModel c = list.get(position);

            t1 = (TextView) view.findViewById(R.id.textView1);
            i1 = (ImageView) view.findViewById(R.id.imageView1);

            t1.setText(c.getAddress());
            String latEiffelTower = c.getLat() + "";
            String lngEiffelTower = c.getLog() + "";
            String url = "http://maps.google.com/maps/api/staticmap?zoom=15&markers="
                    + latEiffelTower
                    + ","
                    + lngEiffelTower
                    + "&size=200x200&sensor=false";
            imgLoader.DisplayImage(url, i1);

            SwipeLayout swipeLayout = (SwipeLayout) view
                    .findViewById(getSwipeLayoutResourceId(position));
            swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {

                @Override
                public void onUpdate(SwipeLayout arg0, int arg1, int arg2) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onOpen(SwipeLayout layout) {

                    Button add, edit, delete;
                    edit = (Button) layout.findViewById(R.id.edit);
                    add = (Button) layout.findViewById(R.id.add);
                    delete = (Button) layout.findViewById(R.id.remove);
                    edit.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            ((MainActivity) getActivity()).addlocation(1,
                                    list.get(position), scase);

                        }
                    });
                    add.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            ((MainActivity) getActivity())
                                    .addlocation(0, scase);

                        }
                    });
                    delete.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            db.removelocation(list.get(position).getL_id());
                            list.remove(position);
                            notifyDataSetChanged();
                        }
                    });
                }

                @Override
                public void onHandRelease(SwipeLayout arg0, float arg1,
                        float arg2) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onClose(SwipeLayout layout) {

                }
            });

        } catch (Exception e) {
            Log.e("111", e.toString());
        }
    }

    @Override
    public View generateView(final int position, ViewGroup arg1) {
        View v = LayoutInflater.from(mContext).inflate(
                R.layout.row_location, null);
        return v;
    }

    @Override
    public boolean isEnabled(int position) {
        if (list.get(position).isIsservisable() == 1) {
            return false;
        } else {
            return false;
        }
    }

    @Override
    public int getSwipeLayoutResourceId(int arg0) {

        return R.id.swipe;
    }
}

@daimajia
Copy link
Owner

Ok, I got the reason of this problem, I'll fix it ASAP.

@daimajia
Copy link
Owner

Hey, guy.
I released v1.0.9, please have a try.

@daimajia daimajia added the bug label Sep 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants