Developing an android app which displays a form with AutoCompleteTextView

Practical - 9
Develop an android app which displays a form to get following information from user.
  • Username
  • Password
  • Email Address
  • Phone Number
  • Country
  • State
  • Gender
  • Interests
  • Birth Date
  • Birth Time
Form should be followed by a Button with label “Submit”. When user clicks the button, a message should be displayed to user describing the information entered. Utilize suitable UI controls (i.e. widgets). [When user enters country in AutoCompleteTextView, list of states should be displayed in Spinner automatically.]



Code:
MainActivity.java

package com.believe.myform;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class ViewData extends AppCompatActivity {

    TextView musername;
    TextView mpassword;
    TextView memail;
    TextView mphoneNumber;
    TextView mcountry;
    TextView mstate;
    TextView mgender;
    TextView minterests;
    TextView mbirthDate;
    TextView mbirthTime;

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

        musername=(TextView)findViewById(R.id.tv_username);
        mpassword=(TextView)findViewById(R.id.tv_password);
        memail=(TextView)findViewById(R.id.tv_email);
        mphoneNumber=(TextView)findViewById(R.id.tv_phone_number);
        mcountry=(TextView)findViewById(R.id.tv_country);
        mstate=(TextView)findViewById(R.id.tv_state);
        mgender=(TextView)findViewById(R.id.tv_gender);
        minterests=(TextView)findViewById(R.id.tv_interests);
        mbirthDate=(TextView)findViewById(R.id.tv_birth_date);
        mbirthTime=(TextView)findViewById(R.id.tv_birth_time);

        Intent intent=getIntent();
        Bundle data=intent.getExtras();
        musername.setText(data.getString("username").toString());
        mpassword.setText(data.getString("password").toString());
        memail.setText(data.getString("email").toString());
        mphoneNumber.setText(data.getString("phone").toString());
        mcountry.setText(data.getString("country").toString());
        mstate.setText(data.getString("state").toString());
        mgender.setText(data.getString("gender").toString());
        minterests.setText(data.getString("interests").toString());
        mbirthDate.setText(data.getString("bdate").toString());
        mbirthTime.setText(data.getString("btime").toString());
    }
}
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:paddingRight="8dp"
    android:paddingLeft="8dp"
    tools:context="com.believe.myform.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <EditText
            android:id="@+id/et_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Username"
            android:ems="10"
            android:layout_marginBottom="8dp"
            android:textSize="18dp"/>

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:ems="10"
            android:inputType="textPassword"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <EditText
            android:id="@+id/et_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email"
            android:ems="10"
            android:inputType="textEmailAddress"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <EditText
            android:id="@+id/et_phone_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Phone Number"
            android:ems="10"
            android:inputType="phone"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <AutoCompleteTextView
            android:id="@+id/actv_country"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Country"
            android:textSize="18dp"
            android:ems="10"
            android:inputType="textAutoComplete"/>

        <Spinner
            android:id="@+id/sp_states"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:spinnerMode="dialog"
            android:textSize="18dp"></Spinner>

        <Spinner
            android:id="@+id/sp_gender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:spinnerMode="dialog"
            android:textSize="18dp"></Spinner>

        <EditText
            android:id="@+id/et_interests"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Interests"
            android:ems="10"
            android:inputType="text"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <TextView
            android:id="@+id/tv_birth_date_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Select your Birth Date:"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <Button
            android:id="@+id/bt_birth_date"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:text="Select Date"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/tv_birth_time_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Select your Birth Time:"
            android:layout_marginBottom="16dp"
            android:textSize="18dp"/>

        <Button
            android:id="@+id/bt_birth_time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:text="Select Date"
            android:textSize="18dp" />

        <Button
            android:id="@+id/bt_submit"
            style="@style/Widget.AppCompat.Button.Colored"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="16dp"
            android:text="Submit"
            android:textSize="18dp" />

    </LinearLayout>
</ScrollView>

ViewData.java
package com.believe.myform;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class ViewData extends AppCompatActivity {

    TextView musername;
    TextView mpassword;
    TextView memail;
    TextView mphoneNumber;
    TextView mcountry;
    TextView mstate;
    TextView mgender;
    TextView minterests;
    TextView mbirthDate;
    TextView mbirthTime;

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

        musername=(TextView)findViewById(R.id.tv_username);
        mpassword=(TextView)findViewById(R.id.tv_password);
        memail=(TextView)findViewById(R.id.tv_email);
        mphoneNumber=(TextView)findViewById(R.id.tv_phone_number);
        mcountry=(TextView)findViewById(R.id.tv_country);
        mstate=(TextView)findViewById(R.id.tv_state);
        mgender=(TextView)findViewById(R.id.tv_gender);
        minterests=(TextView)findViewById(R.id.tv_interests);
        mbirthDate=(TextView)findViewById(R.id.tv_birth_date);
        mbirthTime=(TextView)findViewById(R.id.tv_birth_time);

        Intent intent=getIntent();
        Bundle data=intent.getExtras();
        musername.setText(data.getString("username").toString());
        mpassword.setText(data.getString("password").toString());
        memail.setText(data.getString("email").toString());
        mphoneNumber.setText(data.getString("phone").toString());
        mcountry.setText(data.getString("country").toString());
        mstate.setText(data.getString("state").toString());
        mgender.setText(data.getString("gender").toString());
        minterests.setText(data.getString("interests").toString());
        mbirthDate.setText(data.getString("bdate").toString());
        mbirthTime.setText(data.getString("btime").toString());
    }
}

activity_view_data.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.believe.myform.ViewData">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:orientation="vertical"
        android:gravity="center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Email"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Phone Number"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_phone_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Country"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_country"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="State"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_state"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Gender"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Interests"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_interests"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Birth Date"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_birth_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Birth Time"
        android:layout_gravity="center"
        android:textSize="18dp"/>
    <TextView
        android:id="@+id/tv_birth_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorAccent"
        android:layout_gravity="center"
        android:layout_marginBottom="16dp"
        android:textSize="18dp"/>
    </LinearLayout>
</ScrollView>

Output:






Comments

Popular posts from this blog

Study of DB Miner Tool

Study of WEKA tool

Create calculated member using arithmetic operators and member property of dimension member