Coder Social home page Coder Social logo

Comments (6)

linean avatar linean commented on July 20, 2024

You must remember checked state and set it again when recycler is drawing your layout :)

from shinebutton.

moderateepheezy avatar moderateepheezy commented on July 20, 2024

@linean please can you help me with that, i have no idea how to work that out.

from shinebutton.

ChadCSong avatar ChadCSong commented on July 20, 2024

The select state is control by data. You should add flags or modify data to let view remember you state when you use listView or recyclerView. So you can try to control it by using setChecked(bool) in callBack onBindViewHolder().
Such as:

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {

            holder.shineButton.setChecked(data.get(position).isChecked());

}

from shinebutton.

moderateepheezy avatar moderateepheezy commented on July 20, 2024

its not working, i set a flag already, this what am doing below

   `holder.ivLike.setTag(holder);
    holder.ivLike.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PostsViewHolder viewHolder =(PostsViewHolder) v.getTag();
            if (!isLike) {
                like(postsData.getNews_id());
                viewHolder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) + 1));
                viewHolder.ivLike.setChecked(true);
                isLike = true;
            } else {
                unlike(postsData.getNews_id());
                viewHolder.tvNewsCountLike.setText("" + (Integer.parseInt(holder.tvNewsCountLike.getText().toString()) - 1));
                viewHolder.ivLike.setChecked(false);
                isLike = false;

            }

        }
    });`

from shinebutton.

ChadCSong avatar ChadCSong commented on July 20, 2024

@moderateepheezy
Add boolean property "isLike" in PostsData.
Set this property when you click.
Add control code as follow.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
     holder.shineButton.setChecked(postsDataList.get(position).isChecked());
}

from shinebutton.

ChadCSong avatar ChadCSong commented on July 20, 2024

This is the basic knowledge of listView

from shinebutton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.