gpt4 book ai didi

android - 自定义 ListView 适配器的 ResourceNotFoundException

转载 作者:行者123 更新时间:2023-11-29 14:53:13 26 4
gpt4 key购买 nike

我的列表有这样的 Activity :

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

我想用这些项目制作自定义 ListView :

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

以及我如何在 Activity 中使用它:

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

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

最佳答案

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

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

setText(int resId)
setText(String text)

关于android - 自定义 ListView 适配器的 ResourceNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12408918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com