मेरे पास 2 अलग-अलग प्रकार के लेआउट के साथ ListView है: एक छवि के साथ और छवि के बिना कोई अन्य। मैं this जैसे कुछ करने की कोशिश करता हूं। मैं BaseAdapter की getView ओवरराइड:अलग-अलग आइटम लेआउट के साथ ListViews के लिए ViewHolders
public View getView(int position, View convertView, ViewGroup parent) {
Map<String, String> item = mData.get(position);
if(item.get("image_location").equals("") == true){
ViewHolderWithoutImage holder = new ViewHolderWithoutImage();
if(convertView == null){
convertView = mInflater.inflate(R.layout.row_without_image, null);
holder.title = (TextView)convertView.findViewById(R.id.title);
holder.firstParagraph = (TextView)convertView.findViewById(R.id.first_paragraph);
convertView.setTag(holder);
}else{
holder = (ViewHolderWithoutImage)convertView.getTag();
}
holder.title.setText(mData.get(position).get("title").toString());
holder.firstParagraph.setText(item.get("first_paragraph").toString());
}else{
ViewHolderWithImage holder = new ViewHolderWithImage();
Bitmap bm = null;
if(convertView == null){
convertView = mInflater.inflate(R.layout.row_with_image, null);
holder.title = (TextView)convertView.findViewById(R.id.title_image);
holder.firstParagraph = (TextView)convertView.findViewById(R.id.first_paragraph_image);
holder.image = (ImageView)convertView.findViewById(R.id.image);
convertView.setTag(holder);
}else{
holder = (ViewHolderWithImage)convertView.getTag();
}
holder.title.setText(mData.get(position).get("title").toString());
holder.firstParagraph.setText(item.get("first_paragraph").toString());
String location = imageBaseUrl + item.get("image_location");
bm = downloadImage(location);
holder.image.setImageBitmap(bm);
}
return convertView;
}
मेरे ViewHolders कक्षाएं:
static class ViewHolderWithImage {
TextView title;
TextView firstParagraph;
ImageView image;
}
static class ViewHolderWithoutImage {
TextView title;
TextView firstParagraph;
}
यह दूसरे भाग के बिना काम करता है, लेकिन दुर्घटनाओं जब यह जब item.get("image_location").equals("") != true
java.lang.reflect.InvocationTargetException
साथ भाग में
holder = (ViewHolderWithImage)convertView.getTag();
के लिए जा रहा । कोई विचार मैं इसे कैसे ठीक कर सकता हूं?
getCause() या getTargetException() का उपयोग करने का प्रयास करें (यहां देखें: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/InvocationTargetException.html) अधिक जानकारी प्राप्त करने के लिए अपवाद के बारे में। – MByD