Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After 20 min of hair pulling I found an elegant solution to this problem. First, extend the preference, then override the getView(View convertView, ViewGroup parent) method. My case was this: I had a preference layout with app icon and 2 text views(app name and version). I want to change app version programatically. How do I do this? just take a look below:</p> <pre><code>public class AboutUsPreference extends Preference { public AboutUsPreference(Context context) { super(context); } public AboutUsPreference(Context context, AttributeSet attrs) { super(context, attrs); } public AboutUsPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public View getView(View convertView, ViewGroup parent) { View v = super.getView(convertView, parent); ((TextView)v.findViewById(R.id.textView2)).setText(getAppVersion()); return v; } private String getAppVersion(){ PackageInfo pInfo = null; try { pInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); } catch (NameNotFoundException e) { Log.e(getClass().getName(), e.getMessage(), e); return ""; } String version = pInfo.versionName; return getContext().getString(R.string.version, version); } } </code></pre> <p>The solution is this: <code>View v = super.getView(convertView, parent);</code> when overriding getView method. super.getview call will return your layout view.</p> <p>And my xml preference looks like:</p> <pre><code>&lt;com.audioRec.android.settings.aboutUs.AboutUsPreference android:layout="@layout/about_preference_layout"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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