每次我在意图选择器中选择图像时,我都想将图像放入我的自定义列表视图中。我到这里为止...
public class ItemListBaseAdapter extends BaseAdapter {
private static ArrayList<ItemDetails> itemDetailsrrayList;
private static ArrayList<Uri> imagesUri;
private LayoutInflater l_Inflater;
public ItemListBaseAdapter(Context context, ArrayList<ItemDetails> results, ArrayList<Uri> uri) {
itemDetailsrrayList = results;
imagesUri = uri;
l_Inflater = LayoutInflater.from(context);
}
public int getCount() {
return itemDetailsrrayList.size();
}
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.item_details_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);
holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.price);
holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ArrayList<Uri> lastimageUri = itemDetailsrrayList.get(position).getUriImage();
itemDetailsrrayList.get(position).setUriImage(lastimageUri.get(lastimageUri.size() - 1));
holder.itemImage.setImageURI(itemDetailsrrayList.get(position).getImage());
return convertView;
}
这是我的活动你能帮我吗我认为我在数组列表中添加的 Uri 被复制了
public class ListViewImagesActivity extends Activity {
Button btn_GetPhotos;
private String selectedImagePath;
public Uri imageUri;
ArrayList<Uri> imageUris = new ArrayList<Uri>();
ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
ItemDetails item_details = new ItemDetails();
private final static int SELECT_PICTURE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_GetPhotos = (Button)findViewById(R.id.btn_GetPhotos);
btn_GetPhotos.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Photos"), SELECT_PICTURE);
}
});
}
private ArrayList<ItemDetails> GetSearchResults(){
item_details.setUriImage(ImageListUri());
results.add(item_details);
return results;
}
public ArrayList<Uri> ImageListUri(){
imageUris.add(imageUri);
return imageUris;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE ) {
imageUri = data.getData();
ArrayList<ItemDetails> image_details = GetSearchResults();
//ArrayList<Uri> resultImageUri = ImageListUri();
ItemListBaseAdapter uriItem = new ItemListBaseAdapter(ListViewImagesActivity.this, image_details);
final ListView lv1 = (ListView) findViewById(R.id.listV_main);
lv1.setAdapter(uriItem);
}
}
}
}
但每次我选择一个图像时,它都会显示当前并替换我选择的前一个图像。因此,当我选择图片 4x 时,最新选择的图像出现在我的列表视图 4x 中。我想显示我选择的每张图像,而不仅仅是最新的图像。