2012-09-13 33 views
1

我有这样的活动我的列表:ResourceNotFoundException

<?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); 
    } 

而我得到ResourceNotFoundException在行holder.orderId.setText(order.getOrderid()); 它是什么原因呢?

回答

6

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

的原因的setText()是重载它具有三种版本:

setText(int resId) 
setText(String text) 
+0

谢谢你的人,你给我一个解决方案!!!! –

相关问题