我正在工作json.i成功解析了json并将其保存在Class(get set)中,现在我使用baseadapter在listview中显示我的json值。 我有不同的结果。这意味着在日志中我可以显示不同的项目和适配器不同的
and this is a my listview's picture
在我的选项中我在json解析中没有问题,因为我在" Log"中恢复了我的所有值。但不是适配器 这是我的java代码
public class MoviesRolls extends Fragment {
public final static String TAG = MoviesRolls.class.getSimpleName();
private ListView holllistview;
private HollAdapters adapter;
private ArrayList<CinemaInfoModel> cinemaInfoArray;
public static MoviesRolls newInstance() {
return new MoviesRolls();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.strada_chefs_4, container,
false);
holllistview = (ListView) rootView.findViewById(R.id.holllistview);
showData();
return rootView;
}
private void showData() {
ServerItems mainItem = MainmoviesList.arrayOfList
.get(MainmoviesList.mPosition);
ArrayList<CinemaModel> cinemas = mainItem.getCinema();
for (int i = 0; i < cinemas.size(); i++) {
CinemaModel cinema = cinemas.get(i);
cinemaInfoArray = cinema.getCinemTimeInfo();
for (int j = 0; j < cinemaInfoArray.size(); j++) {
// txt.setText(txt.getText()+timeInfo.getStartTime()+"\n\n\n");
Log.wtf("blblblbllblblbl", cinemaInfoArray.get(j).getHole()
+ "\n\n\n");
}
}
adapter = new HollAdapters(getActivity(), cinemaInfoArray);
holllistview.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
}
这是我的适配器源
public class HollAdapters extends BaseAdapter {
private Context mContext;
private final ArrayList<CinemaInfoModel> hollitems;
private CinemaInfoModel objBean;
TextView textView;
private static LayoutInflater inflater = null;
public HollAdapters(Context context, ArrayList<CinemaInfoModel> hollitems) {
mContext = context;
this.hollitems = hollitems;
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return hollitems.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
grid = new View(mContext);
grid = inflater.inflate(R.layout.cinema_holl_adapter, null);
textView = (TextView) grid.findViewById(R.id.adapter_day);
objBean = hollitems.get(position);
textView.setText(textView.getText()+objBean.getHole());
return grid;
}
} 我不知道自己做错了什么。如果有人知道解决方案,请帮助我 感谢
答案 0 :(得分:0)
您正在创建多个适配器并将所有适配器设置为相同的列表视图 也许您应该将所有数据连接到一个ArrayList中,然后创建并设置适配器。
EDIT
尝试这样的事情:
private void showData() {
ServerItems mainItem = MainmoviesList.arrayOfList
.get(MainmoviesList.mPosition);
ArrayList<CinemaModel> cinemas = mainItem.getCinema();
ArrayList<CinemaInfoModel> infos = new ArrayList<CinemaInfoModel>();
for (int i = 0; i < cinemas.size(); i++) {
CinemaModel cinema = cinemas.get(i);
cinemaInfoArray = cinema.getCinemTimeInfo();
for (int j = 0; j < cinemaInfoArray.size(); j++) {
// txt.setText(txt.getText()+timeInfo.getStartTime()+"\n\n\n");
infos.add(cinemaInfoArray.get(j));
Log.wtf("blblblbllblblbl", cinemaInfoArray.get(j).getHole()
+ "\n\n\n");
}
}
adapter = new HollAdapters(getActivity(), infos);
holllistview.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
我添加了这些内容:
ArrayList<CinemaInfoModel> infos = new ArrayList<CinemaInfoModel>();
infos.add(cinemaInfoArray.get(j));
修改了这个:
adapter = new HollAdapters(getActivity(), infos);
答案 1 :(得分:0)
我认为你的json被正确解析是正确的,问题在于显示它。
你正在循环播放电影院和每个电影院在时间数据上循环播放?我并不真正了解您的数据模型,但在内部循环中构造适配器并将其附加到listview并不正确。
您应该使用循环聚合数据,然后才使用聚合数据构建适配器。