Özel ArrayAdapter'imi bir SlidingTabLayout ile bir ListFragment'te göstermek istiyorum. Daha önce bağdaştırıcıyı normal bir aktivitede test ettim ve iyi çalıştı, ayrıca SlidingTabLayout doğru çalıştı, ancak ListFragment hiçbir şey göstermedi. Bir meteor sunucusundan veri alıyorum ve logcat veri indirildiğini bana göster ...Liste Dizilimi'nde Özel ArrayAdapter Özelliğini Göster
Herhangi bir ipucu var mı?
Bu
benim Fragment Java Kod geçerli:public class MorningFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_morning,container,false);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
MedicationTimeAdapter timeAdapter;
timeAdapter = new MedicationTimeAdapter(getActivity(), R.layout.item_time);
setListAdapter(timeAdapter);
}
}
Ve Fragment XML Kodu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Benim adaptör
public class MedicationTimeAdapter extends ArrayAdapter<MedicationTime> implements DataManager.MedicationCallback {
private static final String LOG_TAG = MedicationTimeAdapter.class.getName();
private final int resourceId;
private final Activity activity;
// private List<MedicationEntry> medications = new ArrayList<MedicationEntry>();
public MedicationTimeAdapter(Activity context, int resource) {
super(context, resource);
resourceId = resource;
activity = context;
}
@Override
public void handleMedicationPlan(List<MedicationEntry> medication) {
// ignore
}
@Override
public void handleMedicationTimes(final List<MedicationTime> medicationTimes) {
// TODO Activity möglicherweise nicht mehr aktiv
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setItems(medicationTimes);
}
});
}
public void setItems(List<MedicationTime> itemList) {
clear();
for (MedicationTime item : itemList) {
add(item);
}
notifyDataSetChanged();
}
@Override
public int getCount() {
return super.getCount();
}
@Override
public View getView(int index, View convertView, ViewGroup parent) {
//data from your adapter
MedicationTime itemData = getItem(index);
if (convertView == null) {
// final LayoutInflater inflater = MHApplication.getLayoutInflater();
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
// TODO mit Referenz Parent-Group erzeugen?! (war für ColorFinder notwendig, um die LayoutParams beim Laden zu erhalten)
// convertView = inflater.inflate(resourceId, parent, false);
convertView = inflater.inflate(resourceId, null);
// prepareInflatedView(convertView);
}
setViewContent(index, convertView, itemData);
return convertView;
}
protected void setViewContent(int index, View itemView, MedicationTime itemData) {
final TextView nameView = (TextView) itemView.findViewById(R.id.time_name);
final TextView medicationView = (TextView) itemView.findViewById(R.id.medication);
int nameId = activity.getResources().getIdentifier("time_name." + itemData.getTimeName(), "string", activity.getPackageName());
nameView.setText(activity.getResources().getString(nameId));
nameView.setText(nameId);
StringBuilder medText = new StringBuilder();
List<MedicationTime.Entry> medications = itemData.getMedications();
for (MedicationTime.Entry medication : medications) {
medText.append(medication.getCount());
medText.append(" * ");
medText.append(medication.getMedicationEntry().getSubstance());
medText.append(" (");
medText.append(medication.getMedicationEntry().getTradingName());
medText.append(")\n");
}
medicationView.setText(medText.toString());
}
Düzenleme:
Problemi çözdüm, adaptörünü Data ile doldurmak için benim anaAktivitemde bir Yöntem var. Sorun, Fragmanımda yeni bir Adaptör oluşturuyordu. Bu yüzden Fragment sınıfımda bir konstrüktör ekledim ve Adaptör'ü ana Etkinliğimden sunarım. Bazı verilerle
public MorningFragment(MedicationTimeAdapter timeAdapter) {
medicationTimeAdapter = timeAdapter;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_morning,container,false);
setListAdapter(medicationTimeAdapter);
return v;
}
bir göz atın [here] (http://stackoverflow.com/questions/16338281/custom-adapter-getview-method-is-not-called/16338380#16338380) – Blackbelt
MedicationTimeAdapter.java sayfasını yazdırabilir misiniz? –
i post tarafından düzenleme – developKinberg