이미지와 두 개의 텍스트가있는 맞춤 환경 설정이 있으며 프로그래밍 방식으로 이미지를 변경해야합니다.맞춤 환경 설정 레이아웃을 관리하는 방법
사용자 정의 환경 설정 뷰를 얻고 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>
코드는 이미지 뷰의 컨텐츠
@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);
이미지를 카메라 또는 sdcard에서 가져올 수 있으며 사용자가 원하는 언제든지 변경할 수 있으므로 드로어 솔루션을 사용할 수 없습니다. 이 코드는 기본 설정을 수정하고, 사용자 정의 레이아웃의 일부 텍스트를 변경하려고 시도했으며 setText ("newText")를 호출 한 후; 디버그하는 동안 TextView에 새 텍스트가 있지만 일단 완료되면 원래 텍스트로 돌아갑니다. – Giuseppe