Pages

Wednesday, May 4, 2016

Android Example with Password in EditBox and Toast



MainActivity.java
package kantapp.androidexamplewithtoast;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
{

    EditText password,show_password;
    Button show_in_toast,show_in_editbox;

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

        password=(EditText)findViewById(R.id.password);
        show_password=(EditText)findViewById(R.id.show_password);

        show_in_editbox=(Button)findViewById(R.id.show);
        show_in_editbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {

                String passwords=password.getText().toString();
                show_password.setText(passwords.toString());
            }
        });

        show_in_toast=(Button)findViewById(R.id.show_toast);
        show_in_toast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String passwords=password.getText().toString();
                Toast.makeText(MainActivity.this, passwords.toString(), Toast.LENGTH_SHORT).show();
            }
        });

        Button reset=(Button)findViewById(R.id.reset);
        reset.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                password.setText("");
                show_password.setText("");

            }
        });
    }
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="kantapp.androidexamplewithtoast.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:text="Wrap content :"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/show_toast"
        android:layout_marginTop="52dp"
        android:text="Match parent"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/show_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView2"
        android:hint="Show Password" />

    <Button
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView"
        android:layout_marginTop="47dp"
        android:text="Show Password in editBox" />

    <Button
        android:id="@+id/show_toast"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/show"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/show"
        android:layout_below="@+id/show"
        android:text="Show password in Toast" />

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView"
        android:ems="10"
        android:hint="Enter Password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/show_password"
        android:layout_marginTop="72dp"
        android:text="Reset" />

</RelativeLayout>

Download Complete Project: 
https://userscloud.com/ulnh7vd8tikc

Download Only Source Code:
 https://userscloud.com/ulg438uzxbjz

No comments:

Post a Comment