Monday, 15 August 2011

android - Manipulating a ListView's items contained in a ViewHolder - Unexpected behaviour -


I am facing some strange behavior in your code that you will find below. I have a button in each of my ListView and if it is clicked, I want to gray the line and hide the button. To make the change permanent, I have set up a property in the custom ViewHolder , so the changes are continuous.

However, if clicking on the button, changes to item 1 will apply. For items 6. It does not affect any other line on other items or it affects more than one line. I suspect that I have something to declare some final variables, but I can not believe it. I tried to apply different solutions (reducing the number of final variables, using different variables, ect), but nothing really does not seem to work.

I need some help. Thanks!

  Loop Adapter Basidator of Public Square Fruit {Private Airlist and Lieutenant; FreeLoptions & gt; the provider; Private activity parents; / ** * Manufacturer * @ Ultimate Parents * Using the Fruit Loop, the parent of the piece will be used as an activity adapter * in one piece, only his parents have access to the data provider. * / Public Frelops adapter (activity guardian) {This porn = parent; Provider = (parent (parent)) .getFruitLoops (); } / ** * Return the way the underlying data provider size * @ Raton * Data Provider Size * {@see android.widget.Adapter # getCount () * / @ Override public int getCount () return provider. (); } / ** {@ Warsaw} * / @ override public object hot itam {return status} {return provider. Gat (status); } / ** {@ Warsaw} * / @ Override public long ITMID (status of return) {Return Status; } / ** * How to create a composite custom view and return it as a view * @see android.widget.Adapter # getView (integer, android.view.View, android.view.ViewGroup) * / @Override public view getView (int position, View convertView, ViewGroup parentViewGroup) {FruitLoopsViewHolder viewHolder; Ultimate Fruit Loops Node Fruit Loops Node = Provider. (Event); If (convertView == faucet) {convertView = LayoutInflater.from (parentViewGroup.getContext ()) increased (R.layout.list_FruitLoops, tap). viewHolder = new FruitLoopsViewHolder ((TextView) convertView.findViewById (R.id.time), (button) convertView.findViewById (R.id.consume), (imageView) convertView.findViewById (R.id.thumbnail), (TextView) Knvertviavkfindviawbyrid (Rkidkkantent_taitl), (Tekstviav) Knvertviavkfindviawbyrid (Rkidkkantent_brif), (Rtingbar) Knvertviavkfindviawbyrid (Rkidkrtingbar)); ConvertView.setTag (viewHolder); } Else {viewHolder = (FreeLops withholder) ConvertViewsagent (); Fixed presentation mode (convertviewview, viewholder); } / ** [Exclude some of the above codes] Setting multiple fields above * / Last Button Button = Viewholder. Gate Button (); Last View Last Convertview = Convertview; button.setOnClickListener (New OnClickListener () {see public void onClick () {button.setEnabled (false); button.setVisibility (View.INVISIBLE); finalConvertView.setAlpha (0.5f); finalConvertView.setBackgroundColor (Color.GRAY);} }); / ** * To use the value of a final view, click the * button to set the value inside the * button, there will be a reason for not updating the images anymore, check the alpha value of the convertview * only to get there The easiest way to do this was because it is a float, * I want to leave some extra padding in the test. * / If (Last Convertview: GetAlpha () <0.9) {viewHolder.setConsumed (true); } Return Convertview; } Private zero setPresentationMode (see convertView, FruitLoopsViewHolder viewHolder) {if (viewHolder.wasConsumed ()) {convertView.setAlpha (0.5f); ConvertView.setBackgroundColor (Color.GRAY); }} <}    

I believe that you reset the alpha to the initial position If the processed () is false.

something like:

  private void set Krenpradrshnmod (See Knhwartwu, fruit lock Dekenholder Dekenholder) {if (viewHolder.wasConsumed ()) {ConvertView.setAlpha (0.5 F ); ConvertView.setBackgroundColor (Color.GRAY); } Else {convertView.setAlpha (1f); // ConvertViews Setbackgram colore (color. WHITE) worth more than //; // or whatever color}}   

Your problem is that you are reusing the same scene, but you will have the same alpha. Placeholder and do not determine the state based on convertView # alpha .

No comments:

Post a Comment