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


On Wed, Jul 11, 2012 at 6:42 AM, Tolriq <[email protected]> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to