2

レイアウトを使用してカスタム設定画面を追加し、値を動的に更新したいという点で、設定アクティビティを作成しています。

コードは次のとおりです。

 <PreferenceCategory
    android:key="more_category"
    android:title="More Wallpapers " >
    <Preference
        android:key="more_apps"
        android:layout="@layout/more_apps" />

これが私のレイアウトですmore_apps.xml

   <?xml version="1.0" encoding="utf-8"?>

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="match_parent"
 >

<TextView
    android:id="@+id/title_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_toRightOf="@+id/image_one"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/description_text"
    android:layout_width="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/title_text"
    android:layout_toRightOf="@+id/image_one"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<ImageView
    android:id="@+id/image_one"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:src="@drawable/launcher" />

実行時にテキストビューと画像を更新したいのですが、設定アクティビティでアクセスするにはどうすればよいですか?

助けてください

4

1 に答える 1

4

以下のコードのように、xmlレイアウトで好みのクラスに言及する必要があります

<PreferenceCategory
   android:key="more_category"
   android:title="More Wallpapers " >

   <com.myapp.myclass  android:key="more_apps"/>

</PreferenceCategory>

com.myappはパッケージ名でありmyclass、すべてのコーディングが含まれるJavaファイルです。

これがJavaコードと膨らんだxmlですmore_apps.xml

  public class myclass extends Preference {

    public myclass(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    }

@Override
protected View onCreateView(ViewGroup parent) {
    // TODO Auto-generated method stub

    LayoutInflater inflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.more_apps, null);

    return view;
  }

 }

このようにして、カスタム設定アクティビティを作成し、あらゆることを行うことができます。

于 2013-01-10T15:46:39.290 に答える