在baseadapter中没有调用这个奇怪的getview问题。
情景:
有趣的是,弹出片段时会触发getView方法 或按下后退按钮。
适配器代码
public class VideCarouselAdapter extends BaseAdapter {
private Context context;
private NavigationFragment nf;
private float scale;
ArrayList<DataModel> videoList = new ArrayList<DataModel>();
public VideCarouselAdapter(Context context,NavigationFragment nf) {
this.context = context;
this.nf=nf;
}
public void setData(ArrayList<DataModel> videoList) {
Timber.log(Log.DEBUG,"VideCarouselAdapter instantiated");
System.out.println(videoList);
this.videoList=videoList;
System.out.println("Total items"+videoList.size());
}
@Override
public Object getItem(int position)
{
return videoList.get(position);
//return VideosCarouselItem.newInstance(context, position, scale,videoList.get(position).getVideoID());
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
Timber.log(Log.DEBUG,"VideCarouselAdapter GEtView");
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.item_coverflow, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.label);
viewHolder.image = (SimpleDraweeView) rowView
.findViewById(R.id.image);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
Uri uri = Uri.parse("http://img.youtube.com/vi/"+videoList.get(position).getVideoID()+"/0.jpg");
Timber.log(Log.DEBUG, "SETTING IMAGE FOR RELATED CAROUSEL "+"http://img.youtube.com/vi/"+videoList.get(position).getVideoID()+"/0.jpg");
holder.image.setImageURI(uri);
holder.text.setText(videoList.get(position).getTitle());
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Timber.log(Log.DEBUG,"Image touched "+parent.getClass().toString());
CoverFlowCarousel coverflow=((CoverFlowCarousel)parent);
int currentSelection=coverflow.getSelection();
if(currentSelection==position) {
nf.presentFragment(VideoInformation.newInstance(videoList.get(position).getVideoID(),videoList.get(position).getTitle(),
videoList.get(position).getDescription()));
return;
};
if(currentSelection<position){
coverflow.fling(Math.round(coverflow.getX()+1200),Math.round(coverflow.getY()));
}else{
coverflow.fling(Math.round(coverflow.getX()-1200),Math.round(coverflow.getY()));
}
}
});
return rowView;
}
@Override
public int getCount()
{
Timber.log(Log.DEBUG,"VideCarouselAdapter COunt "+videoList.size());
return videoList.size();
}
static class ViewHolder {
public TextView text;
public SimpleDraweeView image;
}
}
片段在屏幕上时调试日志
VideCarouselAdapter COunt 12
VideCarouselAdapter COunt 12
VideCarouselAdapter COunt 12
VideCarouselAdapter COunt 12
VideCarouselAdapter COunt 12
调试日志片段被解除
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/kJQqJgGpfeQ/0.jpg
VideCarouselAdapter COunt 15
VideCarouselAdapter COunt 15
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/H403Uyf_TC0/0.jpg
VideCarouselAdapter COunt 15
VideCarouselAdapter COunt 15
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/78x8iOdUdXg/0.jpg
VideCarouselAdapter COunt 15
VideCarouselAdapter COunt 15
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/Pi7NhJE7O_0/0.jpg
VideCarouselAdapter COunt 15
VideCarouselAdapter COunt 15
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/MMg1TpADGBw/0.jpg
VideCarouselAdapter COunt 15
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/j3PwwoTjpNg/0.jpg
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/jB_zCJ2s2jc/0.jpg
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/SrldmVxWu_s/0.jpg
VideCarouselAdapter GEtView
SETTING IMAGE FOR RELATED CAROUSEL http://img.youtube.com/vi/ytka9QZoNAw/0.jpg
子片段内的当前轮播创建代码
private void setupCoverflow(){
Timber.log(Log.DEBUG,"SETTING UP RELATED VIDEOS");
carousel.setSpacing(0.55f);
carousel.setScaleX(1.5f);
carousel.setRotation(0.0f);
adapter = new VideCarouselAdapter(getActivity(),this);
adapter.setData(videoList);
carousel.setAdapter(adapter);
if(carouselCurrentItem==0)
carousel.setSelection(adapter.getCount()/2);
else
carousel.setSelection(carouselCurrentItem);
txtVideoTitle.setText(videoList.get(carousel.getSelection()).getTitle());
carousel.setOnItemSelectedListener(new Carousel.OnItemSelectedListener() {
@Override
public void onItemSelected(View child, int position) {
txtVideoTitle.setText(videoList.get(position).getTitle());
carouselCurrentItem=position;
}
});
}
Mainfragment(工作轮播) https://picasaweb.google.com/lh/photo/_7J6d3winzVWXf8eiAYqxe4jdbH5efcZ8QVU3HGZSEA
Subfragment(类似代码,但轮播确实有效) https://picasaweb.google.com/lh/photo/p12bBck2bDWWFGiHqaZwWe4jdbH5efcZ8QVU3HGZSEA
红色表示轮播视图可见。 正如我在帖子中提到的,数据被加载,getcount事件被调用正确的计数。
答案 0 :(得分:0)
使用
adapter = new VideCarouselAdapter(getActivity(),this);
adapter.setData(videoList);
YOUR_LISTVIEW.setAdapter(adapter);