android viewpage 与listview

yu491290710 yu491290710 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想做一个类似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 才能不出错 求大神指教
...全文
评论 2
收藏 已收藏
分享
返回顶部
yu491290710
Android 80,489 成员 91,375 内容