レイアウトで独自のコンポーネントを使用するアクティビティがあります。これは自分のコンポーネントの xml です。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="@color/patient_view_border"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="8">
<ImageView
android:id="@+id/icons_component"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/_andr"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
このコードを追加してアクティビティをレイアウトし、このコンポーネントを追加してアクティビティをレイアウトします。
<test.test.IconsComponent
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal">
今、extend linearlayout を使用したコンポーネント クラスには、この画像の画像を変更するメソッドがあります。
public void checkActivity(ActivitiesNames name){
if(name == ActivitiesNames.TEST_EXTRA){
testIcon.setImageDrawable(getResources().getDrawable(R.drawable.legendaw_andr));
}
}
私のアクティビティでは、このコンポーネントのオブジェクトを作成し、次の方法でこのメソッドを使用します。
iconsComp = new IconsComponent(getApplicationContext());
iconsComp.checkActivity(ActivitiesNames.TEST_EXTRA);
しかし、私は何の変化も見ません。コンポーネントのアクティビティからアイコンを変更するにはどうすればよいですか? 2 番目の質問: アクティビティからこのコンポーネントにデータを送信するにはどうすればよいですか?