I have two textViews in one xml ie. Customer login and Suppliers login...When i am clicking on cuztomer login or suppliers login pop up should open on that I want to show my login form. Help me out please.
Here is my login form:login_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<include layout="@layout/header_layout" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dip"
android:orientation="vertical" >
<TextView
android:id="@+id/lbl_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dip"
android:gravity="center"
android:textColor="#000000"
android:text="@string/username"
/>
<EditText
android:id="@+id/et_username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="@string/enter_username"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/lbl_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:gravity="center"
android:textColor="#000000"
android:text="@string/password"
/>
<EditText
android:id="@+id/et_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:hint="@string/enter_password"
android:inputType="textPassword"
android:singleLine="true" />
<TextView
android:id="@+id/lbl_forgot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:gravity="center"
android:textColor="#000000"
android:text="@string/forgot_password"
android:textSize="18dp"
/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dip"
android:text="@string/login"
/>
</LinearLayout>
</LinearLayout>
Here is LoginActivity.java:
package com.Login;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
public class LoginActivity extends Activity {
private EditText etUsername, etPassword;
private Button loginButton;
private JSONParser jsonParser;
private static String loginURL = "http://www.xyz.com?login.php";
private Bundle bundle;
private String success;
/** The dialog. */
private ProgressDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
TextView textv = (TextView) findViewById(R.id.lbl_forgot);
textv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(v.getContext(), ForgotPassActivity.class);
startActivity(intent);
}
});
intitDisplay();
addListeners();
}
private void addListeners() {
loginButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (etUsername.getText().length() == 0)
etUsername.setError("please enter username");
if (etPassword.getText().length() == 0)
etPassword.setError("please enter password");
if ((etUsername.getText().length() > 0)
&& (etPassword.getText().length() > 0)) {
jsonParser = new JSONParser();
if (jsonParser.isNetworkAvailable(LoginActivity.this)) {
new BackgroundTask().execute();
} else {
Toast.makeText(LoginActivity.this,
"Network not available", Toast.LENGTH_LONG)
.show();
}
}
}
});
}
private void intitDisplay() {
etUsername = (EditText) findViewById(R.id.et_username);
etPassword = (EditText) findViewById(R.id.et_password);
loginButton = (Button) findViewById(R.id.loginButton);
bundle = new Bundle();
dialog = new ProgressDialog(LoginActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login_layout, menu);
return true;
}
/** calling web service to get creditors list */
/**
* The Class BackgroundTask.
*/
private class BackgroundTask extends AsyncTask<String, Void, String> {
/** The resp. */
String resp;
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onPreExecute()
*/
protected void onPreExecute() {
dialog.setMessage("Loading...");
dialog.setCancelable(false);
dialog.show();
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#doInBackground(Params[])
*/
protected String doInBackground(final String... args) {
Log.v("ENTERED USERNAME::", "" + etUsername.getText().toString());
String newUrl = loginURL + "username="
+ etUsername.getText().toString() + "&password="
+ etPassword.getText().toString();
JSONObject json = jsonParser.getJSONFromUrl(newUrl);
try {
success = json.getString("msg");
Log.v("SUCCESS:: ", success);
if (success.trim().toString().equalsIgnoreCase("SUCCESS")) {
String loggedUsername = json.getString("USER_NAME");
bundle.putString("loggedUser", loggedUsername);
Log.v("Logged User::", loggedUsername);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/*
* (non-Javadoc)
*
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
protected void onPostExecute(String list) {
dialog.dismiss();
if (success.trim().toString().equalsIgnoreCase("SUCCESS")) {
Toast.makeText(LoginActivity.this, "Login Succesfull..",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(LoginActivity.this,
HomeActivity.class).putExtras(bundle);
startActivity(intent);
} else {
Toast.makeText(LoginActivity.this, "Login failed...",
Toast.LENGTH_LONG).show();
}
}
}
}
Use this
Create a new xml file which has the textfields,edittexts,buttons i.e. your login form that you want to show in the popup.Now call the following method where you want to show the popup.
private void callLoginDialog()
{
myDialog = new Dialog(this);
myDialog.setContentView(R.layout.yourxmlfileID);
myDialog.setCancelable(false);
Button login = (Button) myDialog.findViewById(R.id.yourloginbtnID);
emailaddr = (EditText) myDialog.findViewById(R.id.youremailID);
password = (EditText) myDialog.findViewById(R.id.yourpasswordID);
myDialog.show();
login.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//your login calculation goes here
}
});
}
Let me know if it helps you....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With