下面的代码重复最后一个元素4次。此ListView用于选项卡式活动片段。我在网上搜索但没有发现任何帮助。请帮忙!
我的适配器类:
public class MyAdapter extends ArrayAdapter<ElementList> {
public MyAdapter(Context context, ArrayList<ElementList> EventList){
super(context,0,EventList);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_adapter, parent, false);
holder = new ViewHolder();
holder.id = (TextView) convertView.findViewById(R.id.textView9);
holder.name = (TextView) convertView.findViewById(R.id.textView6);
holder.date =(TextView)convertView.findViewById(R.id.textView7);
holder.time =(TextView)convertView.findViewById(R.id.textView8);
convertView.setTag( holder );
} else {
holder = (ViewHolder) convertView.getTag();
}
ElementList elementList = getItem(position);
if(elementList != null) {
holder.id.setText(ElementList.id);
holder.name.setText(ElementList.name);
holder.date.setText(ElementList.date);
holder.time.setText(ElementList.time);
}
return convertView;
}
使用ListView:
ArrayList<ElementList> EventList = new ArrayList<ElementList>();
EventList.add( new ElementList("1","bla1","12/34/45","12:40"));
EventList.add( new ElementList("1","bla2","12/34/45","12:40"));
EventList.add( new ElementList("1","bla3","12/34/45","12:40"));
EventList.add( new ElementList("1","bla4","12/34/45","12:40"));
MyAdapter adapter = new MyAdapter(getActivity(),EventList);
ListView myList = (ListView) rootView.findViewById(R.id.listView);
myList.setAdapter(adapter);
有什么建议吗?
答案 0 :(得分:1)
我想这个
$(document).ready(function() {
$('#myCarousel').carousel({
interval: 10000
});
});
应该是这个
if(elementList != null) {
holder.id.setText(ElementList.id);
holder.name.setText(ElementList.name);
holder.date.setText(ElementList.date);
holder.time.setText(ElementList.time);
}
但是,我不知道这是否会有所帮助。您可以添加一些日志语句,以便在填充后立即查看arrayList中的实际内容,以及适配器准备好从中读取它时。