2017-03-02 2 views
1

StringArrayList<ArrayList<GeofenceDetails>>が複数含まれているカスタムアダプターを作りたいと思います。バインドArrayList <ArrayList<>> Androidのカスタムアダプターで

private ArrayList<Geofences> geofencesArrayList; 
geofencesArrayList = new ArrayList<Geofences>(); 
assetNameArrayList = new ArrayList<ArrayList<GeofenceDetails>>(); 

geofencesArrayList.add(new Geofences(id,name,type,assetNameArrayList)); 
adapter = new GeofenceNameListAdapter(getActivity(),geofencesArrayList); 

adapter.notifyDataSetChanged(); 
geoListView.setAdapter(adapter); 

は、ここで私はgeofencesArrayList上のすべてを見ることができる私のカスタムアダプタ

public class GeofenceNameListAdapter extends ArrayAdapter<ArrayList<Geofences>> { 
    private final Activity context; 
    private final ArrayList<Geofences> geofences; 
    //song list and layout 
    private LayoutInflater view; 
// private static LayoutInflater inflater=null; 

    public static final String PREFERENCES = "RPREFS"; 
    SharedPreferences sharedprefs = null; 
    private String ord_id = null; 
    private String email = null; 

    public GeofenceNameListAdapter(Activity context, 
            ArrayList<Geofences> geofences) { 

     super(context, R.layout.layout_geofence, geofences.size()); 
     // TODO Auto-generated constructor stub 

     finder_sharedprefs = getContext().getSharedPreferences(PREFERENCES, getContext().MODE_PRIVATE); 

     finder_ord_id = finder_sharedprefs.getString("org_id", null); 
     finder_email = finder_sharedprefs.getString("email", null); 

     this.context = context; 
     this.geofences = geofences; 
    } 
    public View getView(final int position, View view, ViewGroup parent) { 

     LayoutInflater inflater = context.getLayoutInflater(); 
     View rowView = inflater.inflate(R.layout.layout_geofence, null, true); 

     TextView txtTitle = (TextView) rowView.findViewById(R.id.name); 
     TextView txtType = (TextView) rowView.findViewById(R.id.type);rowView.findViewById(R.id.delete); 

    txtTitle.setText(geofences.get(position).getTitle()); 
    txtType.setText(geofences.get(position).getType()); 

    return rowView; 
} 

です。ここで私はgeofencesArrayListの印刷データです

for (int l = 0; l<geofencesArrayList.size(); l++) { 
     Log.d("GEOFENCE_DETAILS", geofencesArrayList.get(l).getId().toString()); 
     Log.d("GEOFENCE_DETAILS", geofencesArrayList.get(l).getTitle().toString()); 
     Log.d("GEOFENCE_DETAILS", geofencesArrayList.get(l).getType().toString()); 
    // Log.d("GEOFENCE_DETAILS", geofencesArrayList.get(l).getPoints().toString()); 
     Log.d("GEOFENCE_DETAILS", geofencesArrayList.get(l).getEnforcedData().toString()); 
} 

しかし、問題は、アダプタはデータを表示していません。私はカスタムアダプタで何か問題が起こったと思うが、私はそれを理解できなかった。

私はアドバイスをいただきありがとうございます。教えてください。複数の文字列とArrayList<ArrayList<>>を表示するカスタムアダプタを作成するにはどうしたらいいですか?

ありがとうございます。

+1

コード品質の2つの点:A)命名...あなたの名前に正確な型を入れても意味がありませんB)あなたもあなたのタイプに特定の実装クラスを使いたい; 'private List geofences = new ArrayList <>();'を直接書く方がよいでしょう。読みやすくて使いやすい! – GhostCat

+0

アダプタに間違ったarraylistを送信しているため、データが表示されません。 ArrayList >()を使用してアダプタを初期化するのに対して、ArrayList を使用してGeofenceNameListAdapterコンストラクタを定義しました。 – Alvi

+0

ありがとう@GhostCat。私はそれを行います。 – anuradha

答えて

0

ビューリソースIDとして3-rパラメータを取得するコンストラクタを使用していますが、配列サイズは入れています。

super(context, R.layout.layout_geofence, geofences.size()); 

まず、変更のコンストラクタの呼び出し(場所3-RDパラメータだけR.id.list_itemまたは2パラメータのコンストラクタを使用するようなもの)。

GeofenceNameListAdapterクラスでgetCountメソッドをオーバーライドする必要があります。

@Override 
public int getCount() { 
    return geofences.size(); 
} 
関連する問題