Czy jest możliwe uzyskanie programowego dostępu do układu, który jest ustawiony na Preferencję?Ustawianie układu preferencji i zmiana w nim atrybutu
Oto co mam, bardzo prosty projekt - dowód koncepcji
Activity Pierwszeństwo:
package com.example;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.view.View;
public class PreferenceExampleActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ImageView v = (ImageView) findViewById(R.id.iconka);
}
}
XML zasobu:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="settings">
<PreferenceCategory
android:title="Category Setting Name"
android:order="1"
android:key="Main">
<Preference
android:order="1"
android:title="Setting"
android:summary="Setting1"
android:layout="@layout/profile_preference_row"
android:key="profile" />
</PreferenceCategory>
</PreferenceScreen>
Układ niestandardowy dla preferencji :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/widget_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
<ImageView
android:id="@+id/iconka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
Czego chcę, to móc uzyskać dostęp do obrazu "Iconka" z Aktywności i zmienić z tego miejsca obraz. Używam API 8 (Android 2.2)
Obecnie "v" jest zerowe i nie mam pojęcia, dlaczego tak jest.
Wskazówka jest bardzo cenna!
Aktualizacja - Rozwiązanie: Właściwie potrzebowałem niestandardowej preferencji, którą mogę zmodyfikować zgodnie z moimi potrzebami. Ten jest praktycznym przewodnikiem, jak utworzyć własne niestandardowe preferencje w projekcie: Android & Amir - Android Preferences Zobacz część, w której autor tworzy niestandardową klasę preferencji.
to nie jest ważne dla miodu powyżej, coz PreferenceFragment przychodzi na scenie – gaara87