登錄前我設置的進度條不顯示。我嘗試了很多組合,但仍然無法正常工作。請幫助我,我的工作是在這個線上。我的老闆會殺了我。登錄頁面不顯示進度條
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button login_b1;
private EditText user, pass;
private HandleJSON obj;
String passStr="";
String uname="";
String status="";
SharedPreferences SP;
String key;
public static String getUrlData= new Sql_connect().url();
// Progress Dialog
private ProgressDialog mProgressDialog;
private static final String LOGIN_URL = getUrlData+"windex.php?itfpage=login";
//JSON element ids from repsonse of php script:
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
SharedPreferences SP2 = getSharedPreferences("key",MODE_PRIVATE);
key=SP2.getString("key on click","");
Log.v("key on create",key);
setContentView(R.layout.activity_main);
login_b1=(Button)findViewById(R.id.btnLogin);
user = (EditText)findViewById(R.id.mailid);
pass= (EditText)findViewById(R.id.pass);
login_b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setMessage("Signing In...");
mProgressDialog.show();
uname = user.getText().toString();
Log.v("uname", ""+uname);
passStr = pass.getText().toString();
String finalUrl = LOGIN_URL + "&email="+uname+"&password="+passStr;
Log.v("uname", ""+finalUrl);
try{
obj = new HandleJSON(finalUrl);
obj.fetchJSON();
while(obj.parsingComplete);
status=obj.status();
Log.v("dooStatus",status);
Log.v("doo",""+obj.getRegid());
if(!obj.getRegid().equals(null) && status.equals("success")){
Log.v("do in try block",""+obj.getRegid());
SP = getSharedPreferences("key",MODE_PRIVATE);
SP.edit()
.putString("key on click", obj.getRegid())
.commit();
Log.v("after shared",""+obj.getRegid());
Intent i = new Intent(getApplicationContext(), UserPage.class);
startActivity(i);
}
}catch(Exception e){
e.printStackTrace();
if(status.equals("failed")){
Toast.makeText(getBaseContext(), "Incorrect UserId or Password ", Toast.LENGTH_LONG).show();
}else if(status.equals("inactive")){
Toast.makeText(getBaseContext(), "Please activate your account", Toast.LENGTH_LONG).show();
}
}
mProgressDialog.dismiss();
}
});
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
TextView forgot=(TextView) findViewById(R.id.link_to_forgot);
forgot.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent j = new Intent(getApplicationContext(), ForgotActivity.class);
startActivity(j);
}
});
}
}
使用您的登錄btn行動在asynctask,它可能會給你預期的解決方案。 – prakash 2014-09-24 04:45:47