显示效果:
界面布局:
photo_list.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 需要拍摄照片的列表页面 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="号 码" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="名 称" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="图 片" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="拍 照" />
</LinearLayout>
<ListView
android:id="@+id/lvPhotoList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="完 成"/>
</LinearLayout>
photo_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 照片列表数据项item布局 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="@+id/tvIndex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="车前45度" />
<ImageView
android:id="@+id/ivPhoto"
android:layout_width="100dp"
android:layout_height="86dp"
android:background="@drawable/nopic"
android:gravity="center" />
<Button
android:id="@+id/btnTakePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="拍 照" />
</LinearLayout>
PhotoListAdapter.java
public class PhotoListAdapter extends ArrayListAdapter<PhotoNoList> {
private int carId; //车辆id
public PhotoListAdapter(Context context, int carId) {
super(context);
this.carId = carId;
}
private static final int mLayout = R.layout.photolist_item;
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
final PhotoNoList photoNoList = mList.get(position);
if(convertView == null){
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate( mLayout, null);
viewHolder.tvIndex = (TextView)convertView.findViewById(R.id.tvIndex);
viewHolder.tvName = (TextView)convertView.findViewById(R.id.tvName);
viewHolder.ivPhoto = (ImageView)convertView.findViewById(R.id.ivPhoto);
viewHolder.btnTakePhoto = (Button)convertView.findViewById(R.id.btnTakePhoto);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.tvIndex.setText(photoNoList.getPhotoKindCode() + "");
viewHolder.tvName.setText(photoNoList.getPhotoKind());
viewHolder.ivPhoto.setBackgroundResource(R.drawable.nopic);
viewHolder.btnTakePhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.putExtra("carId", carId);
intent.putExtra("photoKindCode", photoNoList.getPhotoKindCode());
intent.setClass(mContext, TakePhotoActivity.class);
mContext.startActivity(intent);
}
});
return convertView;
}
class ViewHolder {
TextView tvIndex,tvName;
ImageView ivPhoto;
Button btnTakePhoto;
}
}
PhotoListActivity.java
public class PhotoListActivity extends Activity {
ListView lvPhotoList;
DataService dataService;
PhotoListAdapter adapter;
String[] newArrays;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_list);
int carId = getIntent().getIntExtra("carId", 0);
String categoryCode = getIntent().getStringExtra("categoryCode");
lvPhotoList = (ListView)findViewById(R.id.lvPhotoList);
dataService = new DataService(this);
adapter = new PhotoListAdapter(this, carId);
List<PhotoNoList> photoNoList = dataService.queryRequiredPhoto(categoryCode);
Log.d("lb", photoNoList.size() + "");
adapter.setList(photoNoList);
lvPhotoList.setAdapter(adapter);
}
}