-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'類的適配器與問題 –
檢查更新的代碼 –