String
とArrayList<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<>>
を表示するカスタムアダプタを作成するにはどうしたらいいですか?
ありがとうございます。
コード品質の2つの点:A)命名...あなたの名前に正確な型を入れても意味がありませんB)あなたもあなたのタイプに特定の実装クラスを使いたい; 'private List geofences = new ArrayList <>();'を直接書く方がよいでしょう。読みやすくて使いやすい! –
GhostCat
アダプタに間違ったarraylistを送信しているため、データが表示されません。 ArrayList>()を使用してアダプタを初期化するのに対して、ArrayList を使用してGeofenceNameListAdapterコンストラクタを定義しました。 –
Alvi
ありがとう@GhostCat。私はそれを行います。 – anuradha