2017-03-02 6 views
1

StringArrayList<ArrayList<GeofenceDetails>>이 여러 개인 맞춤형 지문을 만들고 싶습니다.바인드 ArrayList <ArrayList<>> 안드로이드의 맞춤 어댑터

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

두 가지 코드 품질 : A) 이름 지정 ... 이름에 정확한 유형 입력시 아무런 의미가 없습니다. B) 또한 ** 특정 유형의 구현 클래스를 사용하고 싶지 않습니다. ; 'private List geofences = new ArrayList <>();'를 직접 작성하는 것이 좋습니다. 읽고 사용하기가 훨씬 쉽습니다! – GhostCat

+0

어댑터에 잘못된 arraylist를 보내므로 데이터가 표시되지 않습니다. ArrayList >()를 사용하여 어댑터를 초기화하는 동안 ArrayList 으로 GeofenceNameListAdapter 생성자를 정의했습니다. – Alvi

+0

감사합니다. @GhostCat. 나는 그렇게 할 것이다. – anuradha

답변

0

보기 리소스 ID로 3-r 매개 변수를 가져 오는 ArrayAdapter 생성자를 사용하고 있지만 배열 크기를 지정하고 있습니다.

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

우선, 변화 생성자 호출 (장소 3 번째 R.id.list_item 같은 매개 변수 일 또는 사용이 파라미터 생성자).

GeofenceNameListAdapter 클래스에서 getCount 메서드를 재정의해야합니다.

@Override 
public int getCount() { 
    return geofences.size(); 
}