Listenin (ListView) üzerinde bazı üstbilgi metinleri (TextView) ekleyebilmem için özel bir Listeyi Görüntüle iletişim kutusu oluşturmam gerekiyor.() OnCreateDialogView ListPreference uzanır ve geçersiz kılar oluşturduğum MyListPreference sınıfı:ListView neden ListPreference iletişim kutusundaki TextView üzerinde kalıyor?
@Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = (View) inflater.inflate(R.layout.dialog_preference_list, null);
return v;
}
My XML düzen dialog_preference_list.xml içerir:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</LinearLayout>
Sorun: TextView'un ListView yerine altında görüntülenir yukarıdaki. Yukarıda olması için TextView'a ihtiyacım var. Ben LinearLayout ve RelativeLayout ("aşağıdaki" veya "yukarıdaki" özniteliklerini kullanarak) hiçbir başarı ile denedim: TextView ListView yukarıda koymak için bir yol bulamıyorum ... Düzeni oldukça basit ve göremiyorum Listenin yukarısında neden kalıyor ... Ayrıca, sorunun hem gerçek bir aygıtta (Nexus 4, Android 4.2.2) hem de emülatörde oluştuğunu unutmayın. Bununla birlikte, Eclipse'in grafiksel düzeninde oluşturulan düzeni incelediğinizde, düzen doğrudur! Ekli fotoğraflara bakın.
Bunu nasıl çözeceğiniz konusunda bir fikrin var mı? Çözelti 10.07.2013 ile
Düzenleme: Eclipse (doğru) işlenen
Düzeni: (yanlış) cihazda oluşturulma
Düzen
Kabul edilen yanıtın önerdiği gibi, sorun, buPersonel'ın onPrepareDialogBuilder() öğesinde builder.setSingleChoiceItems() kullanımından kaynaklanır. ListPreference'ı genişletip onCreateDialogView() öğesini, oluşturucu olmadan Dialog'u oluşturmak için düzeltdim, böylece liste öğelerinin üst kısmındaki üstbilgi metnini gösteren özel bir Görünüm oluşturabilirim.
GPListPreference.java:
public class GPListPreference extends ListPreference {
...
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setNegativeButton(null, null);
builder.setPositiveButton(null, null);
}
private int getValueIndex() {
return findIndexOfValue(getValue());
}
@Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView lv = (ListView) inflater.inflate(R.layout.dialog_preference_list, null);
TextView header = (TextView) inflater.inflate(R.layout.dialog_preference_list_header, null);
header.setText(getDialogMessage()); // you should set the header text as android:dialogMessage in the preference XML
lv.addHeaderView(header);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(), R.layout.dialog_preference_list_singlechoice, getEntries());
lv.setAdapter(adapter);
lv.setClickable(true);
lv.setEnabled(true);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setItemChecked(getValueIndex() + 1, true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setValueIndex(position - 1);
getDialog().dismiss();
}
});
return lv;
}
}
dialog_preference_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
dialog_preference_list_singlechoice.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="2dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="2dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
dialog_preference_list_header.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
Kodu ekledikten Can: dialog_preference_list_header benim durumumda sadece TestView içinde, ama daha karmaşık bir görünüm olabilir ve custom_dialog_single_choice_list_adapter böyle bir şey olabilir
liste için? veya "ListView" anlamına gelen herhangi bir kod – Muzikant
Sadece açık olmak gerekirse, denediniz: "android: layout_above =" @ + id/list "' ve isteğe bağlı olarak, android: layout_alignParentTop = "true" ', TextView, orijinal dialog_preference_list.xml, sağdan mı? – JaKXz
Müthiş cevap! Teşekkürler muslidrikk. – Tiago