我想做一个类似e代驾列表和地图的切换动作
如图:
现在已不加载图片没问题了,viewpage 左右切换也没问题但是当我集成到一起的时候发现问题
TextView lv02 = (TextView)page02.findViewById(R.id.textView1);
lv01.setAdapter(new HomeworkListAdapter(this));
//lv02.setAdapter(new HomeworkListAdapter(this));
//按钮栏
buttons = new Button[pageViews.size()];
buttonsLine = (ViewGroup)inflater.inflate(R.layout.activity_main, null);
button01 = (Button) buttonsLine.findViewById(R.id.pre_one_button);
button02 = (Button) buttonsLine.findViewById(R.id.pre_two_button);
buttons[0] = button01;
buttons[1] = button02; button01.setOnClickListener(new GuideButtonClickListener(0));
button02.setOnClickListener(new GuideButtonClickListener(1));
viewPager = (ViewPager)buttonsLine.findViewById(R.id.guidePages);
setContentView(buttonsLine);
这种写法没问题但是加上我的Listview是报 空指针问题
ImageAndTextListAdapter adapter=new ImageAndTextListAdapter(MainActivity.this, dataArray, lv01);
lv01.setAdapter(adapter);
我知道原因是我没用new...或者说是没用setContentView(buttonsLine);
我的listview的代码如下
public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> { private ListView listView;
private AsyncImageLoader asyncImageLoader; public ImageAndTextListAdapter(Activity activity, List<ImageAndText> imageAndTexts, ListView listView) {
super(activity, 0, imageAndTexts);
this.listView = listView;
asyncImageLoader = new AsyncImageLoader();
} public View getView(int position, View convertView, ViewGroup parent) {
Activity activity = (Activity) getContext(); // Inflate the views from XML
View rowView = convertView;
ViewCache viewCache;
if (rowView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.driver_list, null);
viewCache = new ViewCache(rowView);
rowView.setTag(viewCache);
} else {
viewCache = (ViewCache) rowView.getTag();
}
ImageAndText imageAndText = getItem(position);
// Load the image and set it on the ImageView
String imageUrl = imageAndText.getImageUrl();
ImageView imageView = viewCache.getImageView();
imageView.setTag(imageUrl);
Drawable cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
imageViewByTag.setImageDrawable(imageDrawable);
}
}
});
if (cachedImage == null) {
imageView.setImageResource(R.drawable.icon_home);
}else{
imageView.setImageDrawable(cachedImage);
}
TextView Name = viewCache.getName();
Name.setText(imageAndText.getName());
TextView State = viewCache.getState();
State.setText(imageAndText.getState());
//float MGSS=imageAndText.getMGSS();
RatingBar MGSS1 = viewCache.getMGSS();
MGSS1.setRating(imageAndText.getMGSS());
TextView range = viewCache.getrange();
range.setText(imageAndText.getrange());
TextView count = viewCache.getcount();
count.setText(imageAndText.getcount());
TextView driving_experience = viewCache.getdriving_experience();
driving_experience.setText(imageAndText.getdriving_experience());
TextView address = viewCache.getaddress();
address.setText(imageAndText.getaddress());
TextView drivercode=viewCache.getdrivercode();
drivercode.setText(imageAndText.getdrivercode()); return rowView;
}}
我应该怎么改ImageAndTextListAdapter 才能不出错 求大神指教Androidlistviewimageviewviewpage
如图:
现在已不加载图片没问题了,viewpage 左右切换也没问题但是当我集成到一起的时候发现问题
TextView lv02 = (TextView)page02.findViewById(R.id.textView1);
lv01.setAdapter(new HomeworkListAdapter(this));
//lv02.setAdapter(new HomeworkListAdapter(this));
//按钮栏
buttons = new Button[pageViews.size()];
buttonsLine = (ViewGroup)inflater.inflate(R.layout.activity_main, null);
button01 = (Button) buttonsLine.findViewById(R.id.pre_one_button);
button02 = (Button) buttonsLine.findViewById(R.id.pre_two_button);
buttons[0] = button01;
buttons[1] = button02; button01.setOnClickListener(new GuideButtonClickListener(0));
button02.setOnClickListener(new GuideButtonClickListener(1));
viewPager = (ViewPager)buttonsLine.findViewById(R.id.guidePages);
setContentView(buttonsLine);
这种写法没问题但是加上我的Listview是报 空指针问题
ImageAndTextListAdapter adapter=new ImageAndTextListAdapter(MainActivity.this, dataArray, lv01);
lv01.setAdapter(adapter);
我知道原因是我没用new...或者说是没用setContentView(buttonsLine);
我的listview的代码如下
public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> { private ListView listView;
private AsyncImageLoader asyncImageLoader; public ImageAndTextListAdapter(Activity activity, List<ImageAndText> imageAndTexts, ListView listView) {
super(activity, 0, imageAndTexts);
this.listView = listView;
asyncImageLoader = new AsyncImageLoader();
} public View getView(int position, View convertView, ViewGroup parent) {
Activity activity = (Activity) getContext(); // Inflate the views from XML
View rowView = convertView;
ViewCache viewCache;
if (rowView == null) {
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(R.layout.driver_list, null);
viewCache = new ViewCache(rowView);
rowView.setTag(viewCache);
} else {
viewCache = (ViewCache) rowView.getTag();
}
ImageAndText imageAndText = getItem(position);
// Load the image and set it on the ImageView
String imageUrl = imageAndText.getImageUrl();
ImageView imageView = viewCache.getImageView();
imageView.setTag(imageUrl);
Drawable cachedImage = asyncImageLoader.loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) listView.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
imageViewByTag.setImageDrawable(imageDrawable);
}
}
});
if (cachedImage == null) {
imageView.setImageResource(R.drawable.icon_home);
}else{
imageView.setImageDrawable(cachedImage);
}
TextView Name = viewCache.getName();
Name.setText(imageAndText.getName());
TextView State = viewCache.getState();
State.setText(imageAndText.getState());
//float MGSS=imageAndText.getMGSS();
RatingBar MGSS1 = viewCache.getMGSS();
MGSS1.setRating(imageAndText.getMGSS());
TextView range = viewCache.getrange();
range.setText(imageAndText.getrange());
TextView count = viewCache.getcount();
count.setText(imageAndText.getcount());
TextView driving_experience = viewCache.getdriving_experience();
driving_experience.setText(imageAndText.getdriving_experience());
TextView address = viewCache.getaddress();
address.setText(imageAndText.getaddress());
TextView drivercode=viewCache.getdrivercode();
drivercode.setText(imageAndText.getdrivercode()); return rowView;
}}
我应该怎么改ImageAndTextListAdapter 才能不出错 求大神指教Androidlistviewimageviewviewpage
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货