Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to manage custom preference layout
    text
    copied!<p>I have a custom preference with an image and two text and I need to change the image programmatically.</p> <p>I am able to get the custom preference view and to find the ImageView in the layout using findViewById, but if I try to change the image this do not work.</p> <p>Do I am wrong something?</p> <p><strong>PREFERENCE LAYOUT</strong></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;ImageView android:id="@+id/imageforfacebook" android:layout_width="wrap_content" android:layout_height="match_parent" android:padding="5dip" android:src="@drawable/icon" /&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fadingEdge="horizontal" android:singleLine="true" android:text="titolo" android:textAppearance="?android:attr/textAppearanceSmall" android:textSize="18sp" /&gt; &lt;TextView android:id="@+android:id/summary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@android:id/title" android:layout_below="@android:id/title" android:maxLines="2" android:text="descrizione" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>CODE TO CHANGE THE IMAGEVIEW CONTENT</strong></p> <pre><code>@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { View v = (View) prefs_facebookimage.getView(null, null); ImageView img = (ImageView) v.findViewById(R.id.imageforfacebook); Uri uri = Uri.parse(path); img.setImageURI(uri); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload