这是我的应用程序中的登录页面,现在我想创建注册页面。我认为很容易在登录类中进行更改以创建新的注册类。我已经尝试了很多但无法做到。我之所以想要建立注册页面的原因是在登录类中我与远程服务器成功连接。在注册课程中,我想要另外2个编辑文本字段来重新输入密码和移动设备。同样在登录类中,因为你看到我有复选框但在注册类我不想要复选框。因此我很难转换它。如果有人喜欢帮助我。请试试。
LoginActivity Class -
public class LoginActivity extends Activity {
Intent i;
Button signin, signup;
TextView error;
CheckBox check;
String name = "", pass = "";
byte[] data;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
SharedPreferences app_preferences;
List<NameValuePair> nameValuePairs;
EditText editTextId, editTextP;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
signin = (Button) findViewById(R.id.signin);
editTextId = (EditText) findViewById(R.id.editTextId);
editTextP = (EditText) findViewById(R.id.editTextP);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
check = (CheckBox) findViewById(R.id.check);
String Str_user = app_preferences.getString("username", "0");
String Str_pass = app_preferences.getString("password", "0");
String Str_check = app_preferences.getString("checked", "no");
if (Str_check.equals("yes")) {
editTextId.setText(Str_user);
editTextP.setText(Str_pass);
check.setChecked(true);
}
signin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
name = editTextId.getText().toString();
pass = editTextP.getText().toString();
String Str_check2 = app_preferences.getString("checked", "no");
if (Str_check2.equals("yes")) {
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("username", name);
editor.putString("password", pass);
editor.commit();
}
if (name.equals("") || pass.equals("")) {
Toast.makeText(LoginActivity.this, "Blank Field..Please Enter", Toast.LENGTH_SHORT).show();
} else {
new LoginTask().execute();
}
}
});
check.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now
// checked
SharedPreferences.Editor editor = app_preferences.edit();
if (((CheckBox) v).isChecked()) {
editor.putString("checked", "yes");
editor.commit();
} else {
editor.putString("checked", "no");
editor.commit();
}
}
});
}
public void Move_to_next()
{
startActivity(new Intent(LoginActivity.this, SplashActivity.class));
finish();
}
@SuppressLint("NewApi")
private class LoginTask extends AsyncTask <Void, Void, String>
{
@SuppressLint("NewApi")
@Override
protected void onPreExecute()
{
super.onPreExecute();
// Show progress dialog here
}
@Override
protected String doInBackground(Void... arg0) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://abc.com/login1.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}
inputStream.close();
return buffer.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Hide progress dialog here
if (buffer.charAt(0) == 'Y') {
Toast.makeText(LoginActivity.this, "login successfull", Toast.LENGTH_SHORT).show();
Move_to_next();
} else {
Toast.makeText(LoginActivity.this, "Invalid Username or password", Toast.LENGTH_SHORT).show();
}
}
}
}
答案 0 :(得分:1)
您需要将可见性设置为/不可见/可见,以更改复选框和其他项目的可见性,以满足您的要求。
答案 1 :(得分:0)
您可以根据需要使用相同的setVisibility。
答案 2 :(得分:0)
如果您想使用相同的登录和注册活动,您可以按照以下步骤操作。
在单个xml文件中创建两个子父布局。将Login edittext框放在一个子父布局中,并将Registration edittext框放在另一个子父布局中。
在Activity类中为xml文件中的所有布局,视图和编辑文本框创建ID。
如果用户想要登录页面,则隐藏注册子父布局,并可以看到登录子父布局。
如果用户想要注册页面,则隐藏登录子父级布局和可见注册子父级布局。
为您各自的观点提供点击功能。