ListView未显示所需的记录

时间:2013-11-21 10:29:31

标签: android android-listview

我的ListView一次在UI上保存5条记录,默认情况下它可以作为普通listView.Rowdata滚动包含2个参数名称,状态WHen我显示名称的数据正确但状态为前5个记录随机重复。

listdetails.xml

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:focusableInTouchMode="true"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/timerDisplay"
                android:layout_width="match_parent"
                android:layout_height="370dp"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/media_player_final"
                android:orientation="vertical"
                android:scaleType="fitXY" >
has various textViews & ImageViews
    </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="fill_parent"
                android:layout_height="250dp"
                android:layout_below="@+id/timerDisplay"
                android:orientation="vertical" >

                <ListView
                    android:id="@+id/list"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/timerDisplay"
                    android:layout_marginTop="5dp"
                    android:cacheColorHint="#ffffff"
                    android:divider="@android:color/black"
                    android:dividerHeight="1dp"
                    android:focusable="false"
                    android:scrollbars="none"
                    android:textColor="#000000" />
            </LinearLayout>

ListDetails.java

    listViewLinearLayout=(LinearLayout)findViewById(R.id.linearLayout1);
            Point size = new Point();
            WindowManager w = getWindowManager();

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)    {
                w.getDefaultDisplay().getSize(size);
                height=size.y;
            }else{
                Display d = w.getDefaultDisplay(); 

                height=d.getHeight();
            }
            height=height-350;
            View view_instance = (View)findViewById(R.id.linearLayout1);
            LayoutParams params=view_instance.getLayoutParams();
            params.height=height;
            view_instance.setLayoutParams(params);

And also,
    listView.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;

                case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }

                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }


        });

编辑1 logcat的

11-21 16:34:02.529: I/System.out(9274): Record  0  92.0 %ge
11-21 16:34:02.539: I/System.out(9274): Record  1  0.0 %ge
11-21 16:34:02.539: I/System.out(9274): Record  2  0.0 %ge
11-21 16:34:02.539: I/System.out(9274): Record  3  40.0 %ge
11-21 16:34:02.539: I/System.out(9274): Record  4  0.0 %ge
11-21 16:34:02.539: I/System.out(9274): Record  5  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  6  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  7  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  8  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  9  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  10  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  11  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  12  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  13  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  14  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  15  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  16  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  17  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  18  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  19  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  20  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  21  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  22  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  23  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  24  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  25  NaN %ge
11-21 16:34:02.539: I/System.out(9274): Record  26  NaN %ge
11-21 16:34:02.549: I/System.out(9274): Record  27  NaN %ge
11-21 16:34:02.549: I/System.out(9274): Record  28  NaN %ge
11-21 16:34:02.549: I/System.out(9274): Record  29  NaN %ge

截屏

enter image description here enter image description here enter image description here

调用自定义适配器

CustomAdapter adapter = new CustomAdapter(this, R.layout.episode_list,R.id.textViewAirWayBillNumber, data);

适配器

private class CustomAdapter extends ArrayAdapter<RowData> implements OnClickListener{

        ListView lv;

        public CustomAdapter(Context context, int resource,int textViewResourceId, List<RowData> objects)
        {   
            super(context, resource, textViewResourceId, objects);
            lv=(ListView)findViewById(resource);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent)
        {  
            ViewHolder holder = null;
            TextView status = null;
            TextView awbNumber = null;

            //String name=null;
            TextView imageView=null;


            final RowData rowData= getItem(position);
            if(null == convertView)

            {
                convertView = layoutInflator.inflate(R.layout.episode_list, null);
                holder = new ViewHolder(convertView);
                convertView.setTag(holder);
            }/*else{
                   convertView = getTag();
            }*/

            holder = (ViewHolder) convertView.getTag();

            awbNumber = holder.gettextViewAirWayBillNumber();
            //  //System.out.println("onkar trying to set name"+rowData.intId+""+rowData.StrID+""+rowData.strname);
            awbNumber.setText(rowData.strname );

            status=holder.getEpisodeStatus();


            imageView=holder.getImageViewHolder();
            if(rowData.count==rowData.downloaded){
                //imageView.setText("Play");
            }else{
                float percentage=(float)rowData.downloaded/rowData.count*100;
                status.setText("Downloaded "+Math.ceil(percentage)+" % ");
            }

            return convertView;
        }

        private class ViewHolder  
        {

            protected View mRow;
            protected TextView textViewAirWayBillNumber = null,textView_EpisodeStatus=null, imageView=null;



            public ViewHolder(View row)
            {
                mRow = row;
            }

            public TextView gettextViewAirWayBillNumber()
            {
                if(null == textViewAirWayBillNumber)
                {
                    textViewAirWayBillNumber = (TextView) mRow.findViewById(R.id.textViewAirWayBillNumber);
                }
                return textViewAirWayBillNumber;
            }  

            public TextView getEpisodeStatus(){
                if(null == textView_EpisodeStatus)
                {
                    textView_EpisodeStatus = (TextView) mRow.findViewById(R.id.textView_EpisodeStatus);
                }
                return textView_EpisodeStatus;
            }

            public TextView getImageViewHolder(){
                if(null==imageView){
                    imageView=(TextView)mRow.findViewById(R.id.logo_in_listing);
                }
                return imageView;
            }

        }

        @Override
        public void onClick(View v) {

        }

    }

episode_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="2dp" >

        <TextView
            android:id="@+id/textViewAirWayBillNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dip"
            android:text="name"
            android:textColor="#000000"
            android:textSize="10sp" />

        <TextView
            android:id="@+id/logo_in_listing"
            android:layout_width="25dip"
            android:layout_height="25dip"
            android:layout_alignParentRight="true"
            android:layout_alignBaseline="@+id/textViewAirWayBillNumber"
            android:layout_alignBottom="@+id/textViewAirWayBillNumber"
            android:layout_marginRight="12dip"
            android:textColor="#FF0000"
            android:textSize="10sp" 
            android:layout_marginTop="12dip" />

        <TextView
            android:id="@+id/textView_EpisodeStatus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/textViewAirWayBillNumber"
            android:layout_alignBottom="@+id/textViewAirWayBillNumber"
            android:layout_centerHorizontal="true"
            android:text=""
            android:textSize="10sp" />
    </RelativeLayout>

</LinearLayout>

0 个答案:

没有答案