Don't quite understands the situation. But here is a short example if you 
extends from BaseAdapter and implement in the same line. This is using a 
layout called custom_view (copied bellow). This code is from an Activity 
and can be on the onCreate (The activity must have a ListView called 
listView1
Experiment with different Adapters until you find the one that works better 
for you, all do basically the same but may require less code, depending on 
how much flexibility you need.

 ListView list = (ListView)findViewById(R.id.listView1);
       list.setAdapter(new BaseAdapter(){
           private String values[] = new String[] 
{"VALUE1","VALUE2","VALUE3","VALUE4","VALUE5",
                   "VALUE6", "VALUE7" }; 
           
        public int getCount() {            
            return values.length;
        }

        public Object getItem(int position) {
            return values[position];
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup 
parent) {
            LayoutInflater inflater = getLayoutInflater();
            View view = inflater.inflate(R.layout.custom_view,null);
            TextView tvLine1 = (TextView)view.findViewById(R.id.textView1);
            TextView tvLine2 = (TextView)view.findViewById(R.id.textView2);
            tvLine1.setText(values[position]);
            tvLine2.setText("Line2" + values[position]);
            return view;
        }
           
       });


*File: custom_view.xml*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

On Thursday, July 26, 2012 6:59:05 AM UTC-4, Sergio Panico wrote:
>
> Hi all,
> I need your help to understand the refresh behaviour of a ListView where 
> I've defined a my custom view for the ListView's items.
>
> I think It's better explain it with an example:
> my adapter contains 7 items: A, B, C, D, E, F, G correctly initialized, 
> filled and working. The associated ListView shows 5 (out of 7) items: A, B, 
> C, D, E.
> The problem is that, when I scroll down the ListView's content instead of 
> showing me items F and G, I've got A and B items again. I understood that 
> this is "only" a viewing issue becouse the model elements associated with 
> the last two items, correctly belong to F and G items. :|
>
> Following the ovveride of getView(...) method of my adapter (extending 
> BaseAdapter):
>
> @Override
>     public View getView(int position, View convertView, ViewGroup parent) {
>         MyItemView miv = (( MyItemView  ) convertView);
>
>         if (context == null) return null;
>
>         if (convertView == null) {
>             miv = new MyItemView (........);
>             .....
>         } else {
>             miv.refreshView(); //refresh the view content
>         }
>
>         return miv;
>     }
>
> and the refreshView() method of MyItemView (extending LinearLayout):
>
> @Override
>     public void refreshView() {
>         label1.setText(......);
>         label2.setText(......);
>         label2.setText(......);
>
>         invalidate();
>     }
>
> Thanks a lot to all!
> Bye
> Sergio
>

-- 
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