【问题标题】:How to get values of EditText And RadioButton and send it via HTTP Post如何获取 EditText 和 RadioButton 的值并通过 HTTP Post 发送
【发布时间】:2018-03-26 06:33:12
【问题描述】:

我是 Android 编程新手。有谁能告诉我解决以下问题的方法吗?

我用以下代码制作了一个 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_splash_screen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    tools:context="com.royalrandhawa.xemp.SplashScreen">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="150dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true>

        <EditText
            android:id="@+id/mainSearch"
            android:layout_width="300dp"
            android:textColor="#373737"
            android:textColorHint="#bfbfbf"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:hint="This is your field...."
            android:background="@drawable/mainsearch"
            />

            <Button
            android:text="Surf Now!"
            android:id="@+id/surfNowBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="send"
            />

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <RadioButton
                android:text="Filter Search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/filtersearch"
                android:layout_weight="1"
                android:checked="false"/>
            <RadioButton
                android:text="Trace my activities"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/traceme"
                android:layout_weight="1" />

        </RadioGroup>

    </LinearLayout>

</RelativeLayout>

布局细节是: 用户在 EditText 中输入他的 query,并且在 中还有一些其他选项,例如 Filter SearchTrace Activities单选按钮

我想要这些:

点击Search按钮后,获取EditText的值并检查是否选择了一个或两个radiobuttons然后用 fsVr 和 tmVr 制作两个变量,并将那里的值设置为 true。并开始新的活动名称 结果

之后,使用 HTTP POST 方法将这些值发送到 URL。 并在 Result (Activity)

TextView 中显示服务器响应

谢谢!

【问题讨论】:

  • 您已经准确地解释了您需要做什么。您有什么具体问题吗?
  • 向我们提供一些您尝试过的代码...这样如果您遇到问题我们可以提供帮助...
  • @cvanbeek 我不知道 JAVA 代码我只知道 android studio 中的 XML 文件。请给我完整的 JAVA 代码,这是一个卑微的要求
  • developer.android.com/guide/topics/resources/… 这是关于在您的 java 代码中访问 xml 元素的文档的链接。通过 Google 搜索,您可以找到许多不同的方式来执行 HTTP 请求。根据项目的范围,不同的方法效果最好。
  • 我会警告你,如果不熟悉 java,编写一个 Android 应用程序将非常困难,所以你可能想上一堂关于它的课程

标签: java android android-studio xmlhttprequest


【解决方案1】:

首先你的xml 是错误的。应该是这样的

您需要创建两个不同的RadioGroup,并且两者都只有一个RadioButton,因为您的要求是选择radiobuttons 中的一个或两个

这里有java代码

private void initview1() {

    RadioButton filtersearch = (RadioButton) findViewById(R.id.filtersearch);
    RadioButton traceme = (RadioButton) findViewById(R.id.traceme);
    Button Search_Buttom = (Button) findViewById(R.id.Search_Buttom);
    EditText mainSearch = (EditText) findViewById(R.id.mainSearch);

    Search_Buttom.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Boolean fsVr = false, tmVr = false;
            String search_data = mainSearch.getText().toString();
            fsVr = filtersearch.isChecked();
            tmVr = traceme.isChecked();
// go to your new activity with required data..
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多