2012-05-25 17 views
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); 
} 

} 請指導我如何看到這些表單字段的值。

由於提前

+0

您已經在onCreate()塊之外進行了控制。 –

+0

你應該把你想要的數據,並從其他活動得到它... –

回答

2

在同一acitivty它應該工作,以顯示...

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

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


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

text.setText(email); 

在其他顯示activity你需要通過intentemail傳遞String另一個activitytextview設置類似地

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

+0

+1爲好回覆 – Shraddha

相關問題