現在xmlである文字をタップすると別画面に切り替わる操作を考えております。
現在の状況としてはxmlが
「こちらから →」(完成xml)
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.AppCompatTextView android:id="@+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="1" android:text="こちらから"> </android.support.v7.widget.AppCompatTextView> <ImageView android:id="@+id/test1" android:layout_width="20dp" android:layout_height="20dp" android:layout_margin="10dp" android:layout_toRightOf="@id/test" android:layout_weight="1" android:src="@mipmap/left_arrow"></ImageView> </RelativeLayout>
とJavaが
this.findViewById(R.id.test).setOnClickListener(new OnClickListener() { public void onClick(final View v) { openApp(); } }); this.findViewById(R.id.test1).setOnClickListener(new OnClickListener() { public void onClick(final View v) { openApp(); } });
となっています。
これはこれで動くのですが、もうちょっとスマートに書く方法があればお願いします。
具体的には、xmlで文字とimageを一体化させて、それにIDをつける
もしくはJavaの部分で(ボタン1 または ボタン2).setOnClickListener
として1行にする
などです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。