我遇到问题。我想从除按钮之外的其他活动中的EditText字段更改文本。用按钮更改EditText单击
这是我主要的xml:
<EditText
android:id="@+id/articlename"
android:layout_width="278dp"
android:layout_height="75dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:clickable="false"
android:cursorVisible="false"
android:ems="10"
android:focusable="false"
android:inputType="textMultiLine"
android:text="Name of article"
android:textColor="#FFF"
android:textSize="22dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="16dp"
android:layout_marginTop="108dp"
android:background="@drawable/circle"
android:onClick="onClicknews"
android:text="news\n(click me)"
android:textColor="#FFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
这里我MainActivity其中按钮是:
public void onClicknews(View v) {
Intent intent = new Intent(getApplicationContext(), NewsActivity.class);
String titel1 = "Trumps brutales Kalkül";
EditText news = (EditText) findViewById(R.id.news);
EditText article = (EditText) findViewById(R.id.articlename);
String s = article.getText().toString();
if (s.equalsIgnoreCase(titel1)){
news.setText("Hallo");
}
startActivity(intent);
}
在这里,我的第二个XML其中的EditText是:
<EditText
android:id="@+id/news"
android:layout_width="350dp"
android:layout_height="407dp"
android:layout_marginBottom="23dp"
android:layout_marginEnd="11dp"
android:layout_marginStart="11dp"
android:clickable="false"
android:cursorVisible="false"
android:ems="10"
android:focusable="false"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
我知道有类似的问题,但没有任何soloutions帮助我。
为什么不在第二个活动的意图中将值作为一个Bundle发送,并在onCreate中提取并在那里设置?提供有关您的用例的更多信息... – kRiZ