Я в начале приложения, я абсолютный любитель, и то, что я хочу сделать, просто. Я пытаюсь вытащить Extras из намерения моей первой активности в текстовое представление о моем втором действии Первая страница: как вас зовут? (введите имя и нажмите кнопку) На следующей странице: хорошо, так что ваше имя ... (имя, которое они ввели) У меня был ответ на этот вопрос, но у меня возникли проблемы с его пониманием, в коде, который у меня есть, когда я нажимаю кнопку ладно просто слово хорошо проявляется в TextView, а не отредактированный текст вот мой код ....передать намерение с дополнительным определенным форматом текстового представления
main.java
Button ok;
EditText name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.editText);
ok=(Button)findViewById(R.id.button);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String a=ok.getText().toString();
Intent intent = new Intent(getApplicationContext(), secondactivity.class);
intent.putExtra("NAMEDATA",a);
startActivity(intent);
}
});
}
main.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/okay_button"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:textStyle="bold|italic"
android:textSize="23sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignBottom="@+id/button"
android:hint="@string/text"
android:textSize="25sp"
android:textStyle="bold|italic"
android:layout_toLeftOf="@+id/button"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:src="@drawable/start"
android:contentDescription="@string/startimage"
android:layout_below="@+id/button"
android:paddingBottom="20dp"
android:paddingTop="20dp"/>
</RelativeLayout>
secondactivity.java
public class secondactivity extends Activity {
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t = (TextView)findViewById(R.id.textView3);
String n = this.getIntent().getStringExtra("NAMEDATA");
t.setText(n);
}
activity_second.xml
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".SecondActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name_sent"
android:textSize="23sp"
android:id="@+id/textView2"
android:textStyle="bold|italic"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/what_to_do"
android:id="@+id/textView"
android:layout_marginTop="13dp"
android:textSize="23sp"
android:layout_below="@+id/textView2"
android:textStyle="bold|italic"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bath_time"
android:id="@+id/button"
android:layout_marginTop="29dp"
android:layout_below="@+id/textView"
android:layout_alignRight="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:textSize="25sp"
android:textStyle="bold|italic"
android:onClick="viewimage"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/school"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_alignLeft="@+id/button"
android:textSize="25sp"
android:textStyle="bold|italic"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bed"
android:id="@+id/button3"
android:layout_below="@+id/button2"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:textSize="25sp"
android:textStyle="bold|italic"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:paddingStart="4dp"
android:layout_alignParentRight="true"
android:textSize="23dp"
android:textStyle="bold|italic" />
</RelativeLayout>
androidmainfest.xml
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".secondactivity"
android:label="@string/title_activity_second" >
</activity>
<activity
android:name=".bathactivity"
android:label="@string/title_activity_bath"
android:parentActivityName="com.example.myapplication.SecondActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myapplication.SecondActivity" />
</activity>
</application>
может кто-нибудь сказать мне, где я пошло не так? Думаю, что его в моем OnCreate метод на любой деятельности, но на самом деле застряли, большое спасибо
так, как это исправить ваши изменения? – martinseal1987
Что значит? как вы передаете значение? – Katana24
не уверен? извините и благодарю вас за быстрый ответ. Я не знаю, как добавить содержимое edittext в конец этой строки так же? – martinseal1987