How to get password input using EditText in android

Obtain password in *(Star) from app user.

Android applications are more secure then web browsers because some of websites contain pop up ads and some of them is harmful for unsecured connections. Popup ads active by itself or clicking on any where on web page. Android applications dose not support popup ads . Android apps also support text form box input type password function. With this type of function you can set EditText box input type as password so each & every time after typing password it will show starts *. So here is the complete step by step tutorial for How to get password input using EditText in android.

android-project-download-code-button

How to get password input using EditText in android.

Code for MainActivity.java programming file.

package com.android_examples.com.getpasswordinputstring;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

 Editable HoldPass;
 EditText ThroughPass;
 Button GetPass;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 ThroughPass = (EditText)findViewById(R.id.HoldPassword);
 GetPass = (Button)findViewById(R.id.GetPassword);
 
 GetPass.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 Toast.makeText(MainActivity.this, ThroughPass.getText(), Toast.LENGTH_SHORT).show();
 
 }
 });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
 // Handle action bar item clicks here. The action bar will
 // automatically handle clicks on the Home/Up button, so long
 // as you specify a parent activity in AndroidManifest.xml.
 int id = item.getItemId();
 if (id == R.id.action_settings) {
 return true;
 }
 return super.onOptionsItemSelected(item);
 }
}

Code for activity_main.xml layout file.

 <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="com.android_examples.com.getpasswordinputstring.MainActivity" >

 <EditText
 android:id="@+id/HoldPassword"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="80dp"
 android:ems="10"
 android:inputType="textPassword" >

 <requestFocus />
 </EditText>

 <Button
 android:id="@+id/GetPassword"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Get Password" />

</RelativeLayout>

Screenshot:

How to get password input using EditText in android

Click Here To Download password input using EditText in android Project.

Leave a Reply

Your email address will not be published. Required fields are marked *