Create a "Submit" button after creating a "spinner" with email confirmation

Asked

Viewed 113 times

0

I’m new to creating android apps and wanted your help Crier in the Navigation Drawer one Spinner with 2 text boxes, a drop down list and a button of Submit where this button will have to fetch the answers to the spinner and send to a designated email.

I am blocked in the intention of the button to fetch the information from spinner and send to the email I want. Can help me?

Xml file:

<?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"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@android:color/holo_blue_light">

    <ScrollView
        android:id="@+id/ScrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="100dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="vertical"
            android:layout_height="fill_parent">

            <!--Put form controls here-->

            <TextView
                android:id="@+id/TextViewTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/feedbacktitle"
                android:gravity="center"
                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>

            <Spinner
                android:id="@+id/SpinnerFeedbackType"
                android:layout_height="wrap_content"
                android:prompt="@string/feedbacktype"
                android:layout_width="wrap_content"
                android:entries="@array/feedbacktypelist">
            </Spinner>

            <Button
                android:id="@+id/ButtonSendFeedback"
                android:layout_height="wrap_content"
                android:text="@string/feedbackbutton"
                android:onClick="sendFeedback"
                android:layout_width="wrap_content">
            </Button>

        </LinearLayout>
    </ScrollView>

    <ImageView
        android:layout_width="125dp"
        android:layout_height="125dp"
        app:srcCompat="@mipmap/holistico"
        android:id="@+id/imageView2"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="34dp" />
</RelativeLayout>

Java file:

package com.example.fcarvalho.navigationdrawer;

import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import static android.R.attr.button;
import static com.example.fcarvalho.navigationdrawer.R.id.ScrollView01;
import static com.example.fcarvalho.navigationdrawer.R.id.start;

public class SecondFragment extends Fragment {

    View myView;
    private Spinner Valor;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        myView = inflater.inflate(R.layout.second_layout ,container, false);
        return myView;
            }

    public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);}

        public void sendFeedback(View view) {
            Button button = (Button) findViewById(R.id.ButtonSendFeedback);
            button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    //intenção do botão
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    Uri uri = Uri.parse("mailto:[email protected]?subject=title&body=text");
                }
            });
        }

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

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

        final Spinner feedbackSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType);
        String feedbacktype = feedbackSpinner.getSelectedItem().toString();
    }
}

thank you

  • You have to take the value of the spinner inside the button onclick. And send the data.

  • Thanks Tiago but how do I do it?... I’m sorry but I couldn’t make it?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.