Well must I admit this is the correct way to handle the item row change.  
(Never thought of using *notifyDataSetChanged *on a non changed data to 
force refresh :p)

This will cause 10 or more lines to redraw instead of just a change of 
visibility of one view but since only happening on item click this should 
not hurt too much.

I'll still have the scrolling problem due to async listview refresh but 
since I got the solution for this I'll go on the correct road for adapter 
at least :)

Thanks,
Tolriq.

Le mercredi 11 juillet 2012 18:29:29 UTC+2, MagouyaWare a écrit :
>
> You are not looking at it from the right perspective...  I promise that if 
> you do it the way that I explained it will work.
>
> The listview is nothing more than a visual representation of your data 
> model.  The fact that one item in this list needs to be displayed 
> differently from the rest is something that should be part of the data 
> model.
>
> The adapter's job is to take your data and adapt it to a visual 
> representation.  The getView() method is not called for selection.  The 
> getView() method on the adapter is called by the listview every single time 
> it needs to get that visual representation of your data.
>
> So, again, here are the steps to take to get this working... I have added 
> a few things for clarity:
>
>    1. Subclass an adapter class of your choosing (I usually like to use 
>    BaseAdapter, but I have also subclassed ArrayAdapter before). 
>    2. Have the adapter keep track of the position of the last clicked 
>    item.  I would probably do this by having a member variable on the 
> adapter, 
>    and a getter and setter to change it.  That way, in your onItemClick() 
>    method you can set that value on your adapter, *and then call 
>    notifyDataSetChanged() on your adapter.  This will cause the listview to 
>    refresh itself and call getView() for all the items it needs to display.
>    *
>    3. When you implement getView() on your adapter, check if the current 
>    position is the position of the last clicked item and handle it 
>    appropriately.  *The way I would do what you are trying to accomplish 
>    is as follows:*
>       1. *If the position passed in to getView() is the same as the 
>       member variable that keeps track of the last clicked item, then set the 
>       "gone" part of your view to View.VISIBLE* 
>       2. *If the position passed in to getView() is NOT the same as the 
>       member variable, then set the "gone" part of your view to View.GONE
>       *
>    4. If you do this right, you most likely won't have to deal with all 
>    of the code to manually resize an item in the list...
>    
>
> Thanks,
> Justin Anderson
> MagouyaWare Developer
> http://sites.google.com/site/magouyaware
>
>
> On Wed, Jul 11, 2012 at 10:10 AM, Tolriq <tol...@gmail.com> wrote:
>
>> Thanks for answer.
>>
>> Changing the view is not the problem it's more telling the listview that 
>> the item have changed.
>>
>> I already have a custom Cursor adapter but the getview is not called for 
>> click only for select.
>>
>> The need is to get sure that the listview scroll enough for the entire 
>> row to be visible.
>>
>> Whatever way I'll do the listview would not have the correct information 
>> at the moment i send therequestChildRectangleOnScreen to assure visiblity 
>> of row :(
>>
>> Tolriq.
>>
>>
>> Le mercredi 11 juillet 2012 17:27:21 UTC+2, MagouyaWare a écrit :
>>
>>> I'm not sure I understand exactly what you are trying to do...  But from 
>>> the code you posted, it looks like you are wanting to change the view of 
>>> the last clicked item somehow.  This should really be handled by the 
>>> getView() method of your adapter.  You would need to write a custom adapter 
>>> to do this but that is the correct way to handle something like this.
>>>
>>> Here are some high level steps to help you get started:
>>>
>>>    1. Subclass an adapter class of your choosing (I usually like to use 
>>>    BaseAdapter, but I have also subclassed ArrayAdapter before)
>>>    2. Have the adapter keep track of the position of the last clicked 
>>>    item.  I would probably do this by having a member variable on the 
>>> adapter, 
>>>    and a getter and setter to change it.  That way, in your onItemClick() 
>>>    method you can set that value on your adapter 
>>>    3. When you implement getView() on your adapter, check if the 
>>>    current position is the position of the last clicked item and handle it 
>>>    appropriately.
>>>    4. If you do this right, you most likely won't have to deal with all 
>>>    of the code to manually resize an item in the list...
>>>    
>>> Hope that helps...
>>>
>>> Thanks,
>>> Justin Anderson
>>> MagouyaWare Developer
>>> http://sites.google.com/site/**magouyaware<http://sites.google.com/site/magouyaware>
>>>
>>>
>>> On Wed, Jul 11, 2012 at 6:42 AM, Tolriq <tol...@gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm currently facing a problem and the solution I use does not satisfy 
>>>> me.
>>>> I'm pretty sure there's a correct way to handle this case so I ask here 
>>>> :)
>>>>
>>>> My problem is simple I have a listview with items that have a gone part 
>>>> that I show on the last clicked item.
>>>> This part works well, I also want the clicked item to be fully visible 
>>>> and here's comes trouble.
>>>>
>>>> With non expanding item it's easy to do with 
>>>> requestChildRectangleOnScreen but in my case I can't find a way for the 
>>>> list to be aware of the new size of the item so it will only scroll the 
>>>> item to show the expanded part.
>>>> The solution I use is if the requestChildRectangleOnScreen was in 
>>>> effect or if item is last or before last item then scroll by the size of 
>>>> the expanded item (that i get via measure).
>>>>
>>>> This works but not perfect since sometimes I scroll the list (when i 
>>>> before last item) when it would not have been needed :(
>>>>
>>>> The code used : 
>>>>
>>>>             public void onItemClick(AdapterView<?> arg0, View arg1, int 
>>>>> i, long l) {
>>>>>                 // TODO Auto-generated method stub
>>>>>                 if (curView != null) {
>>>>>                     try {
>>>>>                         curView.setVisibility(View.**GONE);
>>>>>                     } catch (Exception e) {
>>>>>                     }
>>>>>                 }
>>>>>
>>>>>                 ListView listView = (ListView) 
>>>>> findViewById(R.id.mediaslist_**list);
>>>>>
>>>>>                 curView = ((RelativeLayout) 
>>>>> arg1.getTag(R.id.movieslist_**item_details));
>>>>>                 curView.setVisibility(View.**VISIBLE);
>>>>>                 int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, 
>>>>> MeasureSpec.UNSPECIFIED);
>>>>>                 int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, 
>>>>> MeasureSpec.UNSPECIFIED);
>>>>>                 curView.measure(**widthMeasureSpec, 
>>>>> heightMeasureSpec);
>>>>>
>>>>>                 if (listView.**requestChildRectangleOnScreen(**arg1, 
>>>>> new Rect(0, 0, arg1.getRight(),
>>>>>                         arg1.getHeight()), false)
>>>>>                         || listView.**getLastVisiblePosition() <= (i 
>>>>> + 1)) {
>>>>>                     
>>>>> listView.smoothScrollBy(**curView.getMeasuredHeight(), 
>>>>> 150);
>>>>>                 }
>>>>>             }
>>>>>
>>>>
>>>> If someone have the correct way to handle this case thanks for 
>>>> answering :)
>>>>  
>>>> Regards,
>>>> Tolriq.
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to android-developers@**
>>>> googlegroups.com <android-developers@googlegroups.com>
>>>> To unsubscribe from this group, send email to
>>>> android-developers+**unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to