单击“提交”按钮后,在另一页中显示表单数据

时间:2012-05-25 09:42:04

标签: android string android-activity textview

我对android很新,我创建了一个包含3个字段的表单。我想在下一个屏幕或TextView中的同一个屏幕中显示这些字段数据,但我失败了....以下是我的xml代码。

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

     <TextView  
        android:id="@+id/TextViewTitle"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="@string/feedbacktitle"  
        android:textSize="10pt"> 
    </TextView>  
    <EditText  
    android:id="@+id/EditTextName"  
    android:layout_height="wrap_content"  
    android:hint="@string/feedbackname"  
    android:inputType="textPersonName"  
    android:layout_width="fill_parent">  
   </EditText> 
    <EditText  
    android:id="@+id/EditTextEmail"  
    android:layout_height="wrap_content"  
    android:hint="@string/feedbackemail"  
    android:inputType="textEmailAddress"  
    android:layout_width="fill_parent">  
    </EditText> 

    <EditText  
    android:id="@+id/EditTextFeedbackBody"  
    android:layout_height="wrap_content"  
    android:hint="@string/feedbackbody"  
    android:inputType="textMultiLine"  
    android:lines="5"  
    android:layout_width="fill_parent">  
   </EditText> 

    <Button  
    android:id="@+id/ButtonSendFeedback"  
    android:layout_height="wrap_content"  
    android:text="@string/feedbackbutton" 
    android:onClick="sendfeedback" 
    android:layout_width="fill_parent">  
   </Button>  
    <TextView  
    android:id="@+id/TextViewResult"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"    
    android:textSize="10pt"> 
    </TextView>  
    </LinearLayout>  
    </ScrollView>   

以下是Activity类代码

package com.Delegence.FormHandling;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FormHandlingActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

}
TextView Text = (TextView)findViewById(R.id.TextViewResult);
public void sendFeedback(View button) { 

     EditText nameField = (EditText) findViewById(R.id.EditTextName);  
    String name = nameField.getText().toString();  

     EditText emailField = (EditText) findViewById(R.id.EditTextEmail);  
    String email = emailField.getText().toString();  

     EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);  
    String feedback = feedbackField.getText().toString();
    Text.setText(name);
}   

} 请指导我如何查看这些表单字段值。

先谢谢

1 个答案:

答案 0 :(得分:2)

以相同的活动显示它应该有用......

TextView text = (TextView)findViewById(R.id.TextViewResult);

EditText emailField = (EditText) findViewById(R.id.EditTextEmail);


String email = emailField.getText().toString();  

text.setText(email );

要在其他activity中显示,您需要将String email传递给另一个activity intent,并textview同样设置< / p>

1 ----------------

使用意图将数据发送到另一个activity

Intent i = new Intent(this, ActivityTwo.class);

i.putExtra("Value1", "This value one for ActivityTwo ");

i.putExtra("Value2", "This value two ActivityTwo");

2 -----------------------------------

Bundle extras = getIntent().getExtras();
if (extras == null) {
        return;
        }
// Get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
    // Do something with the data
}

http://www.vogella.com/articles/AndroidIntent/article.html