1
public class ListDetails extends ListActivity 
{
    ImageButton imagebutton;
    LoanDetails details;
    ArrayList<String> CreateReqID1, OpenTime1, RequestSummary1, RequestStatus1;
    TextView CreateReqID, OpenTime, RequestSummary, RequestStatus;
    ListView list;
     public void onCreate(Bundle savedInstanceState) 
        {       
            super.onCreate(savedInstanceState);
            setContentView(R.layout.listdetails);           



            CreateReqID1 =  (ArrayList<String>) getIntent().getExtras().get("details1");
            OpenTime1 = (ArrayList<String>) getIntent().getExtras().get("details2");
            RequestSummary1 = (ArrayList<String>) getIntent().getExtras().get("details3");
            RequestStatus1 = (ArrayList<String>) getIntent().getExtras().get("details4");

            setListAdapter(new MyAdapter(this, R.layout.requestlistview));        
            }

     private class MyAdapter extends ArrayAdapter<String> {

            public MyAdapter(Context context, int resource) {
                super(context, resource);           

            }
                @Override
                public View getView(final int position, View convertView, ViewGroup parent) {

                    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    final View row = inflater.inflate(R.layout.requestlistview, parent, false);


                    Log.i("values set", "success");
                    CreateReqID = (TextView) row.findViewById(R.id.createReq);
                    OpenTime = (TextView) row.findViewById(R.id.openTime);
                    RequestSummary = (TextView) row.findViewById(R.id.requestSumary);
                    RequestStatus = (TextView) row.findViewById(R.id.status);


                    CreateReqID.setText(CreateReqID1.get(position));
                    OpenTime.setText(OpenTime1.get(position));  
                    RequestSummary.setText(RequestSummary1.get(position));
                    RequestStatus.setText(RequestStatus1.get(position));        

                    return row;
                }           
            }
}

我有上面的代码可以将数据添加到列表视图中,但是我的 getview 方法没有被调用,请告诉我原因。

我的 listview xml 如下所示

<ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageView2"
        android:layout_alignRight="@+id/imageButton5"
        android:layout_below="@+id/textView1" >

我的列表布局格式如下所示

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFFFF" >


    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="12dp"
        android:layout_x="10dp"
        android:layout_y="60dp"
        android:text="RequestSummary"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000"
        android:textColorLink="#000000" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="11dp"
        android:layout_x="10dp"
        android:layout_y="85dp"
        android:text="RequestStatus"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000"
        android:textColorHint="#000000" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="11dp"
        android:layout_x="10dp"
        android:layout_y="35dp"
        android:text="OpenTime"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="15dp"
        android:layout_x="10dp"
        android:layout_y="10dp"
        android:text="CreateReqID"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/createReq"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"
        android:layout_marginLeft="29dp"
        android:layout_toRightOf="@+id/textView4"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000"
        android:textColorHint="#000000" />

    <TextView
        android:id="@+id/requestSumary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView4"
        android:layout_alignBottom="@+id/textView4"
        android:layout_alignLeft="@+id/createReq"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/requestSumary"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/openTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/createReq"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#000000" />

</RelativeLayout>

我想动态填充文本视图,我得到了数组列表中的所有内容,但我的 getView 方法没有被调用。

4

2 回答 2

1

您没有将字符串数组传递给ArrayAdapter..ArrayAdapter使用传递的列表来计算要在视图中显示的项目数..

查看ArrayAdapter的 javadoc 。您要么需要将对象数组发送到其构造函数,要么调用add()方法之一将对象添加到适配器。

于 2012-11-22T06:06:08.040 回答
1

您错过了getCount()adatper的方法。只需覆盖getCount方法并返回适当的计数。以下方法将强制您的getView被调用5次

@Override
    public synchronized int getCount() {
        return 5;
    }
于 2012-11-22T06:08:01.817 回答