我正在使用supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
并显示或隐藏ProgressBar,我正在使用setSupportProgressBarIndeterminateVisibility()
。
动机是,一旦验证了电子邮件地址就会被发送到服务器,同时等待来自服务器的响应并显示ProgressBar。获得响应后,ProgressBar将被隐藏。
我的代码应该有效。请看下面。
public class LoginActivity extends ActionBarActivity {
String response = "";
String emailAddress, Password;
EditText email, password;
Button sign_in;
TextView register, forgotPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
sign_in = (Button) findViewById(R.id.sign_in);
register = (TextView) findViewById(R.id.register);
forgotPassword = (TextView) findViewById(R.id.forgotPassword);
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
}
});
sign_in.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
emailAddress = email.getText().toString();
Password = password.getText().toString();
if (!emailAddress.equals("") && !Password.equals("")){
setSupportProgressBarIndeterminateVisibility(true);
try {
response = new Connection().execute().get().toString();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
if (response.equals("Credentials Validated!")) {
setSupportProgressBarIndeterminateVisibility(false);
Toast.makeText(LoginActivity.this, response, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, Home.class);
intent.putExtra("emailAddress", emailAddress);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
finish();
startActivity(intent);
} else {
setSupportProgressBarIndeterminateVisibility(false);
final AlertDialog alertDialog = new AlertDialog.Builder(
LoginActivity.this).create();
// Setting Dialog Title
alertDialog.setTitle("We need your attention!");
// Setting Dialog Message
alertDialog.setMessage(response);
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.ic_launcher);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
alertDialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
}
}
else {
if(emailAddress.equals("")) {
email.setError("Email Address Cannot Be Empty!");
}
else
if(Password.equals("")){
password.setError("Password Cannot Be Empty!");
}
}
}
});
}
private class Connection extends AsyncTask {
@Override
protected String doInBackground(Object[] objects) {
LoginJSONParser loginJsonParser = new LoginJSONParser();
return loginJsonParser.getJson(emailAddress, Password);
}
}
}
答案 0 :(得分:0)
替换:
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="proximity" />
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />
<Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />
</Device>
</DeviceCapability>
而不是
setSupportProgressBarIndeterminateVisibility(true);
因为您扩展了ActionBarActivity。 (因为您使用的是supportRequestWindowFeature而不是requestWindowFeature)