【问题标题】:How to display my inputted data after clicking "submit" button?点击“提交”按钮后如何显示我输入的数据?
【发布时间】:2015-04-16 05:14:17
【问题描述】:

如果我问的问题太愚蠢,我真的很抱歉,我真的不是编程专业人士,但我很努力。所以这是我的问题,我创建了这两种布局。

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="#E0E0E0" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="53dp"
    android:ems="14"
    android:inputType="textPersonName" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_alignParentTop="true"
    android:layout_marginTop="14dp"
    android:text="Name:"
    android:textAppearance="?android:attr/textAppearanceLarge" />

 <TextView
     android:id="@+id/textView2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/editText1"
     android:layout_alignTop="@+id/myRadioGroup"
     android:layout_marginLeft="19dp"
     android:layout_marginTop="16dp"
     android:text="Gender:"
     android:textAppearance="?android:attr/textAppearanceMedium" />

 <RadioGroup
     android:id="@+id/myRadioGroup"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@+id/editText1"
     android:layout_centerHorizontal="true"
     android:layout_marginTop="16dp"
     android:checkedButton="@+id/sound" >

     <RadioButton
         android:id="@+id/sound"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Male" />

     <RadioButton
         android:id="@+id/vibration"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Female" />
 </RadioGroup>

 <TextView
     android:id="@+id/textView3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/textView2"
     android:layout_below="@+id/myRadioGroup"
     android:layout_marginTop="22dp"
     android:text="Known Computer Languages:"
     android:textAppearance="?android:attr/textAppearanceMedium" />

 <CheckBox
     android:id="@+id/checkBox1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/textView3"
     android:layout_below="@+id/textView3"
     android:layout_marginTop="18dp"
     android:text="C#" />

 <CheckBox
     android:id="@+id/checkBox2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/checkBox1"
     android:layout_below="@+id/checkBox1"
     android:text="C++" />

 <CheckBox
     android:id="@+id/checkBox3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/checkBox2"
     android:layout_below="@+id/checkBox2"
     android:text="Java" />

 <CheckBox
     android:id="@+id/checkBox4"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/checkBox3"
     android:layout_below="@+id/checkBox3"
     android:text="JavaScript" />

 <CheckBox
     android:id="@+id/checkBox5"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignRight="@+id/textView3"
     android:layout_alignTop="@+id/checkBox1"
     android:text="Python" />

 <CheckBox
     android:id="@+id/checkBox6"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignBaseline="@+id/checkBox2"
     android:layout_alignBottom="@+id/checkBox2"
     android:layout_alignLeft="@+id/checkBox5"
     android:text="Ruby" />

 <CheckBox
     android:id="@+id/checkBox7"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignBaseline="@+id/checkBox3"
     android:layout_alignBottom="@+id/checkBox3"
     android:layout_alignLeft="@+id/checkBox6"
     android:text="PHP" />

 <CheckBox
     android:id="@+id/checkBox8"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/checkBox7"
     android:layout_alignTop="@+id/checkBox4"
     android:text="SQL" />

 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"
     android:layout_marginBottom="23dp"
     android:text="Next Page" />

这是另一个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" 
 android:background="#E0E0E0">

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="15dp"
    android:text="How long have you been learning programming?"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:ems="10" >

</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="16dp"
    android:text="What programming language are you most interested in?"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText2"
    android:layout_below="@+id/editText2"
    android:layout_marginTop="16dp"
    android:text="Programming language you find easy"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView3"
    android:layout_below="@+id/textView3"
    android:ems="10" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText3"
    android:layout_below="@+id/editText3"
    android:layout_marginTop="15dp"
    android:text="Programming language you find difficult"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText
    android:id="@+id/editText4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView4"
    android:layout_below="@+id/textView4"
    android:ems="10" />

<ToggleButton
    android:id="@+id/toggleButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView5"
    android:layout_below="@+id/textView5"
    android:layout_marginLeft="29dp"
    android:layout_marginTop="14dp"
    android:text="ToggleButton" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/editText4"
    android:layout_alignTop="@+id/toggleButton1"
    android:text="Submit" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText4"
    android:layout_below="@+id/editText4"
    android:layout_marginTop="16dp"
    android:text="Please toggle on the button if you want to view the inputs after submission, toggle off if not."
    android:textAppearance="?android:attr/textAppearanceSmall" />

所以我的问题是,在第一个布局中,我希望能够在单击下一步后,我应该能够移动到下一个布局。 (还没做,因为我真的不知道怎么做,试着关注一些 youtube 视频,但我真的无法理解它们)假设我连接了 2 个布局,然后我继续下一个布局。最后包含一个“提交”按钮,我希望能够让用户选择他/她是否想立即显示他们输入到布局 1 和 2 中的数据。我在布局 2 中放置了一个切换按钮,其中这意味着,如果在单击提交之前切换按钮处于“打开”状态,它应该立即显示他们输入的所有数据,包括问题。如果他们在点击提交之前关闭切换按钮,它应该只在底部显示一个小文本通知,例如“表单成功提交”。

如果我问了这么多问题和一大堆文字,我真的很抱歉。我的老师对我的期望太高了,我尽我所能。 (好吧,也许不是“太多”我可能只是编程学习缓慢)谢谢大家。顺便说一句,我正在使用 eclipse..

【问题讨论】:

  • 发布您的活动源代码。
  • 您应该开始阅读 Intents (which is useful to move between activity)Button listenertoggle 主题来执行此操作。您可以从here 开始。尽管我们提供帮助,但如果您犯了一个错误,例如缺少点,您将无法理解如何调试。付出一些努力。祝你好运!

标签: java android eclipse android-layout


【解决方案1】:

创建一个类 ModelPerson 来保存一个人的值

public class ModelPerson {
        String name = null;
        String gender = null; //insert the radio button value into this
        //
        //write getter and setter methods for above variables
        }

在活动1中:在提交按钮clickListener()中,启动新的intent,将值放入其中

ModelPerson  personObj  = new ModelPerson();
personObj.setName(editText1.getText.getString);
Intent intent = new Intent(Activity1.this,
                    Activity2.class);
            intent.putExtra("PersonsDetails", personObj)
            startActivity(intent);

在活动 2 中:在 onCreate() 内部使用 getExtra() 方法获取意图值并从模型人员对象中检索值。

【讨论】:

    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2019-02-06
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多