名前とアドレスのテーブルを持つ単純なmysqlデータベースがあり、同じもののjson配列を取得できますが、リストビューにデータを入力できません。私を助けてください
1 に答える
            0        
        
		
コントロールの使用方法とアダプターの使用方法を既に知っていると仮定すると、、、、、およびメソッドを拡張してオーバーライドすることにより、ListViewカスタム アダプターを作成する必要があります。BaseAdaptergetCount()getItem()getItemId()getView()
たとえば、 BaseAdapter の実装は を取り、次のJSONArrayようなものになる可能性があります...
public class JSONAdapter extends BaseAdapter {
   private JSONArray array = null;
   public JSONAdapter(JSONArray data) {
      this.array=data;
   }
   public int getCount() {
      return array.length();
   }
   public Object getItem(int position) {
      return array.get(position);
   }
   public long getItemId(int position) {
      return position;
   }
   public View getView(int position, View currentView, ViewGroup parent) {
      // get the current item from the json array
      JSONObject o = getItem(position);
      // create a new view
      View v;
      if (convertView == null || newItemView) {
         v = inflater.inflate(YOUR_ITEM_LAYOUT_VIEW_ID, parent, false);
      } else {
         v = convertView;
      }
      // populate the view
      // use v.findViewById() to locate your layout items and then
      // set a value from the JSONObject that you obtained above
      return view;
   }
}
ListAdapter上記のコードは、ここでインラインで入力しただけなので、直接コンパイルできない可能性があります (エラー チェックは含まれていません) JSONArray。
于 2012-05-26T12:58:36.610   に答える