android viewpage 与listview

yu491290710 2013-07-30 10:48:35
我想做一个类似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 才能不出错 求大神指教
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yu491290710 2013-07-31
  • 打赏
  • 举报
回复
我检查出来了调用加载listview的方法是位置放错了,纠结了一天
顾小林 2013-07-30
  • 打赏
  • 举报
回复
http://download.csdn.net/detail/shen332401890/5290671 看看是否可以参考

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧