1

我的清单上有这样的活动:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ListView
        android:id="@+id/altOrderslist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
         />
 </RelativeLayout>

我想用这些项目制作自定义列表视图:

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

    <!-- ListRow Left sied Thumbnail image -->

    <LinearLayout
        android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="5dip"
        android:padding="3dip" >

        <TextView
            android:id="@+id/altOrderId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="Rihanna Love the way lie"
            android:textColor="#040404"
            android:textSize="15dip"
            android:textStyle="bold"
            android:typeface="sans" />
    </LinearLayout>

    <!-- Title Of Song -->


    <!-- Artist Name -->

    <TextView
        android:id="@+id/altOrderTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Just gona stand there and ..."
        android:textColor="#343434"
        android:textSize="10dip" />

    <!-- Rightend Duration -->

    <TextView
        android:id="@+id/altOrderStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dip"
        android:gravity="right"

        android:textColor="#10bcc9"
        android:textSize="10dip"
        android:textStyle="bold" />

    <!-- Rightend Arrow -->

    <TextView
        android:id="@+id/altOrderPrice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/thumbnail"
        android:text="Rihanna Love the way lie"
        android:textColor="#040404"
        android:textSize="15dip"
        android:textStyle="bold"
        android:typeface="sans" />

</RelativeLayout>

这是我的适配器类:

 public class OrderAdapter extends ArrayAdapter<Order>{


        Context context; 
        int layoutResourceId;    
        List<Order> orders = null;

        public OrderAdapter(Context context, int layoutResourceId, List<Order> orders) {
            super(context, layoutResourceId, orders);
            this.layoutResourceId = layoutResourceId;
            this.context = context;
            this.orders = orders;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            OrderHolder holder = null;

            if(row == null)
            {
                Log.i("I'm in OrderAdapter",Integer.toString(layoutResourceId));


                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(R.layout.dash_alt_item, parent, false);
                Log.i("I'm in OrderAdapter",Integer.toString(layoutResourceId));
                holder = new OrderHolder();
                holder.orderId = (TextView)row.findViewById(R.id.altOrderId);
                holder.orderTitle = (TextView)row.findViewById(R.id.altOrderTitle);
                holder.orderStatus = (TextView)row.findViewById(R.id.altOrderStatus);
                holder.orderPrice = (TextView)row.findViewById(R.id.altOrderPrice);

                //row.setTag(holder);
            }
            else
            {
                holder = (OrderHolder)row.getTag();
            }

            Order order = orders.get(position);
            holder.orderId.setText(order.getOrderid());
            holder.orderTitle.setText(order.getTitle());
            holder.orderStatus.setText(order.getProcess_status().getProccessStatusTitle());
            holder.orderPrice.setText(Float.toString(order.getPrice()));


            return row;
        }

        static class OrderHolder
        {
            TextView orderId;
            TextView orderTitle;
            TextView orderStatus;
            TextView orderPrice;
        }
    }

以及我如何在我的活动中使用它:

public class DashboardActivityAlt extends Activity{

    static List<Order> orders;
    List<Order> forPrint = new ArrayList<Order>();
    private ListView listView1;



    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.dash_alt);
        try {
            this.getOrderList("1", "10"); **// filling the forPrint list**
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        OrderAdapter adapter = new OrderAdapter(this, 
                 R.layout.dash_alt_item, **forPrint**);
        listView1 = (ListView)findViewById(R.id.altOrderslist);
        listView1.setAdapter(adapter);
    }

我在这行得到 ResourceNotFoundExceptionholder.orderId.setText(order.getOrderid()); 这是什么原因?

4

1 回答 1

6

确保您没有将 int 传递给该方法。将其转换为 String 并将开始按预期工作。

原因是 setText() 重载它有版本:

setText(int resId)
setText(String text)
于 2012-09-13T14:48:52.397 回答