-1
我正在android中创建一个列表。这是我从服务器获取列表,并将其添加到一个ArrayList.After,我创建了一个适配器来显示列表,但问题是,我有总共两个值列表中,但ListView只显示我1项。我检查了很多。我查了适配器。它总共有2个项目,但只显示1.为什么这个问题。请帮忙。从服务器无法在ListView中获取所有值android
//撷取列表
JSONArray askArray = response.getJSONArray("data");
if (askArray.length() > 0) {
final ArrayList<HashMap<String, String>> cameraList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < askArray.length(); i++) {
JSONObject cameraObject = askArray.getJSONObject(i);
//Log.e("TAG", "onResponse: "+cameraObject.getString("description"));
HashMap<String, String> store = new HashMap<String, String>();
store.put(KEY_DESCRIPTION, cameraObject.getString("description"));
cameraList.add(store);
}
//适配器列表视图的
public class AdapterTermsNConditions extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
private Context context;
AskFormFragment askFormFragment;
HashMap<String, String> officeList1;
public AdapterTermsNConditions(Activity a, ArrayList<HashMap<String, String>> d, AskFormFragment askFormFragment) {
activity = a;
data = d;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.askFormFragment = askFormFragment;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = inflater.inflate(R.layout.item_terms_conditions, parent, false);
Log.e("position", +position+"");
TextView txtTerms = (TextView) itemView.findViewById(R.id.txtTerms);
officeList1 = new HashMap<String, String>();
officeList1 = data.get(position);
Log.e("termsList", officeList1.toString() + "" +position);
txtTerms.setText(officeList1.get(AskFormFragment.KEY_DESCRIPTION));
Log.e("TAG", "terms_size: "+data.toString());
return itemView;
}
}
' //你没有显示listview的适配器适配器代码,只有1种方法。 –
分享你的整个listview'类的适配器与问题 –
检查更新的代码 –