copy text field data to other text field Android - android

i need to copy the text field data to another onclick
below is my activitymain,xml of my app
<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=".MainActivity" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:ems="10"
android:inputType="numberSigned" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="63dp"
android:text="Button" />
<Chronometer
android:id="#+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="108dp"
android:text="Chronometer" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>

EditText editText1 = (EditText) findViewById(R.id.editText1);
EditText editText2 = (EditText) findViewById(R.id.editText2);
Button b= (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String data = editText1.getText().toString();
editText2.setText(data);
});
Hope it helps

package com.example.rohitsapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText1 = (EditText) findViewById(R.id.editText1);
final EditText editText2 = (EditText) findViewById(R.id.editText2);
Button b= (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
String data = editText1.getText().toString();
editText2.setText(data);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

Related

How can store Data text view data?

In this file i have two Edit text and one textview.I want to sum two number.then result are show in text view.Then i want to store Textview data. please help.i am trying but i am fail.
Activity_main.xml//
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Edit"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Edit1"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Add"
android:id="#+id/add"
android:onClick="add"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sub"
android:id="#+id/sub"
android:onClick="sub"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:paddingBottom="30dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pr"
android:text="Previoues Data"
/>
</LinearLayout>
</LinearLayout>
the java file is
MainActivity.java
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
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.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText Edit,Edit1;
Button add, sub, pr;
TextView view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Edit = (EditText) findViewById(R.id.Edit);
Edit1 = (EditText) findViewById(R.id.Edit1);
add = (Button) findViewById(R.id.add);
sub = (Button) findViewById(R.id.sub);
pr = (Button) findViewById(R.id.pr);
view = (TextView) findViewById(R.id.view);
Edit.setText("0");
add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int value1 = Integer.parseInt(Edit.getText().toString());
int value2 = Integer.parseInt(Edit1.getText().toString());
int result = value1 + value2;
view.setText(Integer.toString(result));
// Edit.setText(Integer.toString(result));
SharedPreferences sharedPreferences=getSharedPreferences("Mydata",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putInt("value",result);
editor.commit();
}
});
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int value1 = Integer.parseInt(Edit.getText().toString());
int value2 = Integer.parseInt(Edit1.getText().toString());
int result = value1 - value2;
view.setText(Integer.toString(result));
Edit.setText(Integer.toString(result));
}
});
pr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences sharedPreferences=getSharedPreferences("Mydata",Context.MODE_PRIVATE);
// int defaultValue = getResources().getInteger(R.string.saved_high_score_default);
String v=sharedPreferences.getInt("value","");
view.setText(v);
}
});
}
}
update your xml file remove onClick from your button
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Add"
android:id="#+id/add"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sub"
android:id="#+id/sub"
/>
Problem is with your getting value from sharedPreference
String v=sharedPreferences.getInt("value","");
why are you passing string as default value and your
try this String
v = Integer.toString(sharedPreferences.getInt("value",0));
in the layout you´ve got android:onClick="add" there should be a public void add(View v) to handle the event. Do the sum inside that handler.
Please, follow the documentation
http://developer.android.com/reference/android/widget/Button.html and see the :onCLick handling.

Unfortunately app has stopped ! when i try to insert some codings into the mainActivity class

![error ][1]
package com.welcome.testingnew;
import android.app.Activity;
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.R;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText username;
final EditText password;
username=(EditText) findViewById(R.id.EditText1);
password=(EditText) findViewById(R.id.EditText2);
final EditText result=(EditText) findViewById(R.id.EditText3);
Button login=(Button) findViewById(R.id.button1);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(username.toString().equals("thamarai") && password.toString().equals("selva")){
EditText3.setText("Success");
}
else
EditText3.setText("failed");
}
});
}
}
Tried: if i run projetc with below codes it works fine
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
}
and if i insert anycode after the
setContentView(R.layout.activity_main);
like this
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText username;
final EditText password;
username=(EditText) findViewById(R.id.EditText1);
password=(EditText) findViewById(R.id.EditText2);
final EditText result=(EditText) findViewById(R.id.EditText3);
Button login=(Button) findViewById(R.id.button1); }
}
it makes Unfortunately app has stopped problem please answer me as soon as possible
I guess you're trying to achieve this. Here's the working code :
activity_main.xml
<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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="28dp"
android:text="Username"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="30dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginLeft="28dp"
android:layout_toRightOf="#+id/textView1"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignLeft="#+id/editText1"
android:layout_alignRight="#+id/editText1"
android:inputType="textPassword" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Login" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceLarge" />
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
EditText username;
EditText password;
TextView status;
Button log;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.editText1);
password = (EditText) findViewById(R.id.editText2);
status = (TextView) findViewById(R.id.textView3);
log = (Button) findViewById(R.id.button1);
log.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String uname = username.getText().toString();
String pass = password.getText().toString();
if(uname.equals("admin") && pass.equals("admin"))
{
status.setText("Success");
}
else
{
status.setText("failed");
}
}
});
}
}
When app starts,
When validation fails,
When validation success,
Hope it helps!

Password protect android app

I have an application which I am developing. I need to password protect it, i.e. a password needs to be entered before allowing access to the main content.
Password can be stored locally in the Java file.
LoginActivity.java
package com.example.capitacustomerfactsheets;
import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class LoginActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_login);
final EditText passWord = (EditText) findViewById(R.id.editpassword);
final Button loginButton = (Button) findViewById(R.id.btn_submit);
loginButton .setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(passWord.getText().toString().equals("123456")) {
final Intent myIntent = new Intent();
myIntent.setComponent(new ComponentName(LoginActivity.this,MainActivity.class));
startActivity(myIntent);
finish();
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
}
activity_login.xml
<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=".LoginActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password" />
<EditText
android:id="#+id/editpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<Button
android:id="#+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="Login" />
</RelativeLayout>
try this one
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.activity_login);
final EditText passWord = (EditText) findViewById(R.id.editpassword);
final Button loginButton = (Button) findViewById(R.id.btn_submit);
loginButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(passWord.getText().toString().equals("123456")) {
final Intent myIntent = new Intent();
myIntent.setComponent(new ComponentName(LoginActivity.this,your new activity.class));
startActivity(myIntent);
finish();
}
}
});
}

Function doesn't display the correct solution in android app, can someone tell me what I'm doing wrong?

The program should take in a length, width, and depth measurement from the user and then display how many gallons of water the tank can hold. However, when I do something like "12,12,14" for the measurements, it gives me some ridiculously large number instead of something around 15 gallons. Here is the main activity:
package com.example.aquariumconverter;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText gallonText = (EditText) findViewById(R.id.editText1);
String strlen = String.valueOf(R.id.editText2);
String strwid = String.valueOf(R.id.editText3);
String strdep = String.valueOf(R.id.editText4);
double length = Double.parseDouble(strlen);
double width = Double.parseDouble(strwid);
double depth = Double.parseDouble(strdep);
RectangularTank recTank = new RectangularTank(length,width,depth);
final String strConvertedToGallons = recTank.convertToGallons(length,width,depth);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
gallonText.setText(strConvertedToGallons);
}
});
}
#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;
}
}
And here is the rectangulartank class:
package com.example.aquariumconverter;
import android.view.View;
import android.widget.Button;
public class RectangularTank{
public RectangularTank(double length, double width, double depth) {
super();
init(length, width, depth);
}
private void init(double length, double width, double depth)
{
convertToGallons(length, width, depth);
}
public String convertToGallons(double length, double width, double depth)
{
double feetLength = length / 12.0;
double feetWidth = width / 12.0;
double feetDepth = depth / 12.0;
double gallonAmount = feetLength * feetWidth * feetDepth * 7.47;
String strGallonAmount = String.valueOf(gallonAmount);
return strGallonAmount;
}
}
Here is an updated version of the Main activity after some suggestions:
package com.example.aquariumconverter;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText gallonText = (EditText) findViewById(R.id.editText1);
EditText editText2Text = (EditText) findViewById(R.id.editText2);
EditText editText3Text = (EditText) findViewById(R.id.editText3);
EditText editText4Text = (EditText) findViewById(R.id.editText4);
double length, width, depth;
try {
length = Double.valueOf(editText2Text.getText().toString());
width = Double.valueOf(editText3Text.getText().toString());
depth = Double.valueOf(editText4Text.getText().toString());
} catch (NumberFormatException e){
length=0;
width=0;
depth=0;
}
RectangularTank recTank = new RectangularTank(length,width,depth);
final String strConvertedToGallons = recTank.convertToGallons(length,width,depth);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
gallonText.setText(strConvertedToGallons);
}
});
}
#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;
}
}
Here is the xml:
<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=".MainActivity" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:text="Width"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="22dp"
android:text="Depth"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="Rectangular Tank"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="54dp"
android:layout_toLeftOf="#+id/textView1"
android:text="Length"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_alignLeft="#+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignLeft="#+id/editText2"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView4"
android:layout_alignLeft="#+id/editText3"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Convert" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textMultiLine" />
</RelativeLayout>
Try this..
String strlen = String.valueOf(R.id.editText2);
This is not the correct way to get the text from EditText
You need to initilize the EditText then you need to get the text from the EditText by this editText2Text.getText().toString().trim()
EditText editText2Text = (EditText) findViewById(R.id.editText2);
EditText editText3Text = (EditText) findViewById(R.id.editText3);
EditText editText4Text = (EditText) findViewById(R.id.editText4);
String strlen = editText2Text.getText().toString().trim();
String strwid = editText3Text.getText().toString().trim();
String strdep = editText4Text.getText().toString().trim();
EDIT 1:
try{
length = Double.parseDouble(editText2Text.getText().toString());
width = Double.parseDouble(editText3Text.getText().toString());
depth = Double.parseDouble(editText4Text.getText().toString());
}catch (NumberFormatException e){
length=0;
width=0;
depth=0;
}
EDIT 2:
I have found out the problem.. You have not got the text from edittext on button click. Try to get it in button click. It will work..
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
length = Double.parseDouble(editText2Text.getText().toString());
width = Double.parseDouble(editText3Text.getText().toString());
depth = Double.parseDouble(editText4Text.getText().toString());
}catch (NumberFormatException e){
length=0;
width=0;
depth=0;
}
RectangularTank recTank = new RectangularTank(length,width,depth);
final String strConvertedToGallons = recTank.convertToGallons(length,width,depth);
gallonText.setText(strConvertedToGallons);
}
});

Customize keyboard in android?

Hello every one i am new in android and i want to customize android key board in the following manner. I want to three buttons previous , next & done above the default keyboard of android. Can we customize default keyboard of android in such manner?
thanks in advance
my pic:
well after so much of googling and finding various question on stackoverflow i get what i am looking for and i am posting all the thing which i had created .
my activity class
package com.example.demoappkeyboard;
import org.w3c.dom.Text;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.InputType;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText ed1,ed2,ed3;
EditText edit3,edit4,edit5;
// private Button sub1 , sub2 , sub3;
private EditText[] bed = {ed1,ed2,ed3};
private static int i = 1,j = 3 , k = 0 ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog alertDialog = new Dialog(MainActivity.this);
ed1 = (EditText) findViewById(R.id.editText1);
ed2 = (EditText) findViewById(R.id.editText2);
ed3 = (EditText) findViewById(R.id.editText3);
edit3 = (EditText) findViewById(R.id.edit3);
ed1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
initiatePopupWindow("");
}
});
ed2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
initiatePopupWindow("");
}
});
ed3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
initiatePopupWindow("");
}
});
}
#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;
}
protected void initiatePopupWindow(String value) {
final String data ="";
final Button sub1,sub2, sub3;
final EditText edit3;
final EditText ed1,ed2,ed3;
final RelativeLayout bottom1;
final Dialog alertDialog = new Dialog(MainActivity.this);
final LinearLayout mainlayout;
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.setContentView(R.layout.screen_popup);
edit3 = (EditText) alertDialog.findViewById(R.id.edit3);
mainlayout = (LinearLayout)alertDialog.findViewById(R.id.popup_element);
sub1 = (Button) alertDialog.findViewById(R.id.submit1);
sub2 = (Button) alertDialog.findViewById(R.id.submit2);
sub3 = (Button) alertDialog.findViewById(R.id.submit3);
bottom1 = (RelativeLayout) alertDialog.findViewById(R.id.linearLayout3);
Button cancel = (Button) alertDialog.findViewById(R.id.btncancel);
Button submitbtn = (Button) alertDialog.findViewById(R.id.btnsubmit);
ed1=(EditText)findViewById(R.id.editText1);
ed2=(EditText)findViewById(R.id.editText2);
ed3=(EditText)findViewById(R.id.editText3);
if(ed1.hasFocus())
{
String s1 = ed1.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
sub1.setEnabled(true);
}
if(ed2.hasFocus())
{
String s1 = ed2.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_NUMBER);
}
if(ed3.hasFocus())
{
String s1 = ed3.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
}
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
if (value.equals("")) {
edit3.setHint("Please enter Username");
} else {
edit3.setText(value);
int textLength = edit3.getText().length();
edit3.setSelection(textLength, textLength);
}
alertDialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
alertDialog.show();
//edittext click event
edit3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
bottom1.setVisibility(View.VISIBLE);
sub1.setVisibility(View.VISIBLE);
sub2.setVisibility(View.VISIBLE);
sub3.setVisibility(View.VISIBLE);
}
});
//button click event
submitbtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(ed1.hasFocus())
{
String data1 = edit3.getText().toString();
ed1.setText(data1);
edit3.setText(data1);
}
if(ed2.hasFocus())
{
String data1 = edit3.getText().toString();
ed2.setText(data1);
edit3.setText(data1);
}
if(ed3.hasFocus())
{
String data1 = edit3.getText().toString();
ed3.setText(data1);
edit3.setText(data1);
}
final String value = edit3.getText().toString().toUpperCase();
// usern.setText(value);
alertDialog.cancel();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.cancel();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
});
sub1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(i==1)
{
ed1.requestFocus();
String s1 = ed1.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
sub1.setEnabled(true);
sub2.setEnabled(false);
//j=3;
}
i++;
if(i==2)
{
ed2.requestFocus();
String s1 = ed2.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_NUMBER);
i=2;
sub1.setEnabled(true);
sub2.setEnabled(true);
}
if(i==3)
{
ed3.requestFocus();
String s1 = ed3.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
//i=0;
sub1.setEnabled(false);
sub2.setEnabled(true);
i=0;
}
}
});
sub2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
j--;
if(j==1)
{
ed1.requestFocus();
sub2.setEnabled(false);
sub1.setEnabled(true);
String s1 = ed1.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
j=4;
}
if(j==2)
{
sub2.setEnabled(true);
sub1.setEnabled(true);
ed2.requestFocus();
String s1 = ed2.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_NUMBER);
}
if(j==3)
{
sub2.setEnabled(true);
sub1.setEnabled(false);
ed3.requestFocus();
String s1 = ed3.getText().toString();
edit3.setText(s1);
edit3.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
sub3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mainlayout.getWindowToken(), 0);
bottom1.setVisibility(View.INVISIBLE);
}
});
}
}
my main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:background="#ffffff">
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="50dp">
</RelativeLayout>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:background="#ffffff"
>
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:text="Name"
android:maxLength="10"
android:inputType="text"
>
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:text="Phone"
android:maxLength="10"
android:inputType="number"
/>
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="14dp"
android:imeOptions="actionNext"
android:text="Email"
android:maxLength="10"
android:inputType="text"
>
<requestFocus />
</EditText>
</LinearLayout>
</ScrollView>
<!--for bottom bar -->
<RelativeLayout android:layout_height="50dp"
android:gravity="center" android:layout_width="match_parent"
android:id="#+id/linearLayout2" android:background="#ffffff"
>
</RelativeLayout>
</LinearLayout>
my screen_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup_element"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight=".2"
android:gravity="bottom|center_horizontal"
android:orientation="vertical"
>
<EditText
android:id="#+id/edit3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:maxLength="10"
android:singleLine="true"
android:inputType="text"
>
<requestFocus />
</EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:maxLength="10"
android:singleLine="true"
android:inputType="text"
android:visibility="invisible"
>
</EditText>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:maxLength="10"
android:singleLine="true"
android:inputType="text"
android:visibility="invisible"
>
</EditText>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight=".8"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center" >
<Button
android:id="#+id/btnsubmit"
android:layout_width="137dp"
android:layout_height="40dp"
android:text="Submit"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center" >
<Button
android:id="#+id/btncancel"
android:layout_width="137dp"
android:layout_height="40dp"
android:text="Cancel"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<RelativeLayout android:layout_height="50dp"
android:gravity="bottom" android:layout_width="match_parent"
android:id="#+id/linearLayout3" android:background="#ffffff"
android:visibility="invisible"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal"
>
<Button
android:id="#+id/submit1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Next"
android:visibility="invisible"
android:layout_weight=".3"
android:layout_gravity="left"
>
</Button>
<Button
android:id="#+id/submit2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Previous"
android:visibility="invisible"
android:layout_weight=".3"
android:layout_gravity="center"
>
</Button>
<Button
android:id="#+id/submit3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Done"
android:visibility="invisible"
android:layout_weight=".3"
android:layout_gravity="center"
>
</Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Categories

Resources