SORU
14 Mart 2011, PAZARTESİ


Nasıl bir PreferenceScreen (Android)için bir düğme eklemek için

Kalkınma Android ve Tercihleri rastladım oldukça yeniyim. PreferenceScreens buldum ve bir oturum açma işlevselliği ile oluşturmak istedim. Ekleyebilirim sıcak bilmiyorum bu benim tek sorun bir "Giriş" PreferenceScreen için düğme. Tercih benim görüşüm gibi görünüyor:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
...
    <PreferenceScreen android:title="@string/login" android:key="Login">
        <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference>
        <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference>
    </PreferenceScreen>
...
</PreferenceScreen>

Düğmesine iki ExitTextPreferences altında doğru olmalıdır.

Bu sorun için basit bir çözüm var mı? Bulduğum tek çözüm alt Tercihi Ekranlar kullandığım için çalışıyordu.

Güncelleme:

Düğmeler bu şekilde ekleyebilirim olduğunu anladım:

<PreferenceScreen android:title="@string/login" android:key="Login">
        <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference>
        <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference>
        <Preference android:layout="@layout/loginButtons" android:key="loginButtons"></Preference>
</PreferenceScreen>

ve düzeni dosyası (layoutButtons.xml şöyle görünüyor:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:weightSum="10" 
    android:baselineAligned="false" android:orientation="horizontal">
    <Button android:text="Login" android:layout_width="fill_parent"
        android:layout_weight="5" android:layout_height="wrap_content"
        android:id="@ id/loginButton" android:layout_gravity="left"></Button>
    <Button android:text="Password?" android:layout_width="fill_parent"
        android:layout_weight="5" android:layout_height="wrap_content"
        android:id="@ id/forgottenPasswordButton"></Button>
</LinearLayout>

Şimdi düğmeleri görünür ama kodda onlara erişemiyorum. FindViewByİd ile denedim() ama bu boş dönüyor. Bu düğmeleri erişim nasıl herhangi bir fikir?

CEVAP
31 AĞUSTOS 2011, ÇARŞAMBA


Xml:

<Preference android:title="Acts like a button"
                android:key="@string/myCoolButton"
                android:summary="This is a cool button"/>

onCreate() java için

Preference button = (Preference)findPreference(getString(R.string.myCoolButton));
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {   
                    //code for what you want it to do   
                    return true;
                }
            });

Bu aitmiş gibi görünmesi sadece başlık ve özet ile normal bir Tercih gibi görünüyor.

Düzenleme:En iyi derleyici hizmetleri, dil çeviri ve Dize değişiklikleri kolaylığı için kaynaklarını kullanmak için çünkü @string/myCoolButton getString(R.string.myCoolButton) kullanarak değiştirdim.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Angry Paintballer

    Angry Paintb

    8 Ocak 2012
  • ImBluecams

    ImBluecams

    25 Kasım 2012
  • TheOtherMau5

    TheOtherMau5

    6 Mart 2012