我有两个布局,我的UI将显示菜单栏
-----------------------------------------------------
| |
| Button 1 |
-----------------------------------------------------
| | |
| S1 | S2 |
-------------------------------------------------------
| |
| EditText |
--------------------------------------------------------
我的上半部分的XML
-----------------------------------------------------
| |
| Button 1 |
-----------------------------------------------------
| | |
| S1 | S2 |
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ag.ap.tagassigner.TagAssignmentHolder">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
“文本”字段位于片段中,并且位于另一种布局
中-------------------------------------------------------
| |
| EditText |
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ag.ap.tagassigner.TagAssignment">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/serialNoField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp"
android:hint= "@string/serialno_plh"
/>
我在菜单栏中有按钮
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto/android">
<!-- Refresh -->
<item android:id="@+id/action_refresh"
android:icon="@drawable/ic_menu_camera"
android:title="@string/action_barcode"
app:showAsAction="ifRoom"
android:onClick="scanBarcode"
/>
<!-- Help -->
<item android:id="@+id/action_help"
android:icon="@drawable/ic_menu_camera"
android:title="@string/action_camera"
app:showAsAction="ifRoom"
/>
</menu>
如果点击按钮1,我想填充editText的值。我如何实现它?
答案 0 :(得分:0)
我有同样的问题。为此尝试将您的活动更改为片段并放入框架,之后在您的活动中使用此框架,这将从按钮单击更改您的editText值。对于其他片段的按钮单击,尝试使用buttoName.performClick()。希望这个能帮助你。