3

そこで、設定アクティビティの設定の 1 つにカスタム設定ビューを作成しました。

<Preference 
      android:key="facebook_sharing"
      android:layout="@layout/fb_pref_item"/>

そのカスタム設定レイアウトで ImageView をプログラムで編集できるようにしたい (設定自体の値に基づいて.

次のようになります。

Preference facebookItem = (Preference)findPreference("facebook_sharing");
facebookItem.setOnPreferenceChangeListener(this);

RelativeLayout rl = //get relative layout someway or another...

mFacebookIcon = (ImageView)rl.findViewById(R.id.fb_imgview);
if(!mFacebookConn.isSessionValid())
    mFacebookIcon.setColorFilter(R.color.transparent_black);

そのコメント行を引き出す方法がわかりません。私は次のことを試しました:

RelativeLayout rl = (RelativeLayout)facebookItem.getView(null, null); //dont know what the params ought to be...

RelativeLayout rl = (RelativeLayout)findViewById(facebookItem.getLayoutResource());

どちらも機能しません。私は周りを検索しましたが、これを試した人を見つけることができないようです. 何か案は?ありがとう!

編集: fb_pref_item の提供:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fb_view"
    android:layout_width="match_parent"
    android:layout_height="68dp" >

    <TextView android:id="@+id/fb_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="2dp"
        android:layout_alignParentTop="true"
        android:text="@string/facebook"
        android:textSize="20sp"
        android:textColor="@color/item_view_text_color" />

    <TextView android:id="@+id/fb_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="8dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/fb_title" />

    <ImageView android:id="@+id/fb_imgview"
        android:src="@drawable/facebook64"
        android:layout_width="42dp"
        android:layout_height="42dp"
        android:layout_centerVertical="true"
        android:layout_margin="12dp"  
        android:layout_alignParentRight="true" 
        android:scaleType="centerInside"
        android:contentDescription="@string/cd_icon"/>


</RelativeLayout>
4

1 に答える 1

0

これまでに提供された情報に基づいて (上記のコメントを参照してください。fb_pref_item.xmlソースを投稿することをお勧めします。また、 が複数ImageViewあるのか、1 つだけなのかを示していませんでした)、正しいビューを探していないように思えます。 . これの代わりに:

RelativeLayout rl = //get relative layout someway or another...
mFacebookIcon = (ImageView)rl.findViewById(R.id.fb_imgview);

この不要なものをRelativeLayout完全に無視して、次のように直行できるはずfb_imgviewです。

mFacebookIcon = (ImageView) this.findViewById(R.id.fb_imgview);

この場合、最初のものを見つけようとするのではなく、から直接継承する継承されfindViewById(int)たメソッドを使用することに注意してください。PreferenceActivityActivityRelativeLayout

ビューを生成するPreference#getView()ために使用されるため、メソッドを使用することはできません(ビューは で所定の位置にレンダリングされます)。ビューが既にレンダリングされた後、ビューを取得するためには使用されません。PreferenceActivity

于 2012-07-15T01:02:56.937 に答える