मेरे पास एक छवि और दो टेक्स्ट के साथ एक कस्टम वरीयता है और मुझे प्रोग्राम को प्रोग्रामेटिक रूप से बदलने की आवश्यकता है।कस्टम वरीयता लेआउट का प्रबंधन कैसे करें
मैं कस्टम वरीयता दृश्य प्राप्त करने और findViewById का उपयोग कर लेआउट में ImageView को खोजने में सक्षम हूं, लेकिन अगर मैं छवि को बदलने की कोशिश करता हूं तो यह काम नहीं करता है।
क्या मुझे कुछ गलत है?
वरीयता लेआउट
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageforfacebook"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="5dip"
android:src="@drawable/icon" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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" />
<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" />
</LinearLayout>
</LinearLayout>
कोड imageView सामग्री
@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);
मैं ड्रॉबल समाधान का उपयोग नहीं कर सकता क्योंकि छवि कैमरे या एसडीकार्ड से ली जाएगी और यह किसी भी समय उपयोगकर्ता को बदल सकती है। कोड वरीयता से बाहर काम करता है, मैंने अपने कस्टम लेआउट में कुछ टेक्स्ट बदलने की कोशिश की है, और जब मैं setText ("newText") को कॉल करता हूं; डीबग के दौरान टेक्स्ट व्यू में नया टेक्स्ट होता है, लेकिन एक बार खत्म होने पर यह मूल के रूप में वापस आता है। – Giuseppe