Inflate ListView row from OnClickListener in Android?

后端 未结 2 460
执念已碎
执念已碎 2020-12-07 05:40

I have a class (A_Main.java) extending ArrayAdapter. I set my ListView to use A_Main as it\'s ListAdapter. I

2条回答
  •  粉色の甜心
    2020-12-07 06:21

    Edit:

    Solution is probably simple Take boolean array globally like this

     private final boolean[] selectedstates;
    

    And initialize it with the size of your list in your constructor

     selectedstates= new boolean[yourlist.size()];
    

    And in out side of onclick listener set like this

     yourbutton.setSelected(selectedstates[position]);
    

    I hope this will help you


    Try this

    Take a custom selector with two different state images for selection and non selection

    
    
    
        
        
    
    

    1.Create a global variable

    Imageview previous; 
    

    in your Custom Adapter and Initialize it in the constructor where you'll get the content

    previous=new ImageView(context);
    

    Add in your adapter getView() method you will probably have a onclickListener for your Imageview do like this

     imagPlay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 ImageView current=((ImageView)v);
                  current.setSelected(true);
                  previous.setSelected(false);
                  previous=current;
            }
        });
    

    This will work, I was confident because I have used it in my app. I hope this will help you

提交回复
热议问题