2

我对 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>   

以下是活动类代码

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);
}   

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

提前致谢

4

1 回答 1

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给另一个activityintent并设置textview

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

于 2012-05-25T09:43:18.240 回答