私は私のリストでそのような活動をしています:
<?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());
します。その理由は何ですか。