-4

谁能告诉我如何登录?我尝试使用用户名Priyanka和密码登录,Priyanka但不成功。

谁能帮我吗?

package org.example.rig_parking;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
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;

 public class Rig_ParkingActivity extends Activity {

String username,password;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/semibold.ttf");
        TextView myTextView = (TextView)findViewById(R.id.rig_parkmain);
        myTextView.setTypeface(myTypeface);
        TextView forget_main = (TextView)findViewById(R.id.forget_main);
        forget_main.setTypeface(myTypeface);
        final EditText email_main = (EditText)findViewById(R.id.email_main);
        email_main.setTypeface(myTypeface);
        final EditText password_main = (EditText)findViewById(R.id.password_main);
        password_main.setTypeface(myTypeface);

        Button copy=(Button) findViewById(R.id.copyright);
        copy.setText("(c)Rig Parking 2010-2012,All Rights Reserved");
        copy.setTypeface(myTypeface);

        TextView register=(TextView) findViewById(R.id.register_main);       
     register.setTypeface(myTypeface);

        register.setOnClickListener(new OnClickListener() {         
        public void onClick(View arg0) {

     Intent register=new Intent(getApplicationContext(),Register.class);    
     startActivity(register);               
        }
    });

 /*      forget_main.setOnClickListener(new OnClickListener() {         
        public void onClick(View arg0) {

     Intent register=new Intent(getApplicationContext(),Tab.class); 
     startActivity(register);               
        }
    });
        */
        TextView login=(TextView) findViewById(R.id.login_main);       
        login.setTypeface(myTypeface);
        login.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            username=email_main.getText().toString();
            password=password_main.getText().toString();

            if(username.equals("")&&password.equals(""))
            {
                final AlertDialog alertDialog51;                    
                  alertDialog51 = new AlertDialog.Builder(Rig_ParkingActivity.this).create();
                    alertDialog51.setMessage(Html
                       .fromHtml("<font color='#00beb4'><b> Enter Email and Password</b></font>"));                                                                                                     
                    alertDialog51.setButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                int which) {                            
                        alertDialog51.dismiss();    
                               }
                         });            
                    alertDialog51.setButton2("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        alertDialog51.dismiss();                                                
                       }
                    });                         
                    alertDialog51.show();                           
            }                                   
            else if(username.equals(""))
             {
                final AlertDialog alertDialog51;                    
                  alertDialog51 = new AlertDialog.Builder(Rig_ParkingActivity.this).create();
                    alertDialog51.setMessage(Html
                       .fromHtml("<font color='#00beb4'><b>    Enter Email    </b></font>"));                                                                                                       
                    alertDialog51.setButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                int which) {                            
                        alertDialog51.dismiss();    
                               }
                         });            
                    alertDialog51.setButton2("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        alertDialog51.dismiss();                                                
                       }
                    });                         
                    alertDialog51.show(); 
             }
            else if(password.equals(""))
             {
                final AlertDialog alertDialog51;                    
                  alertDialog51 = new AlertDialog.Builder(Rig_ParkingActivity.this).create();
                    alertDialog51.setMessage(Html
                       .fromHtml("<font color='#00beb4'><b>    Enter  Password   </b></font>"));                                                                                                        
                    alertDialog51.setButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                int which) {                            
                        alertDialog51.dismiss();    
                               }
                         });            
                    alertDialog51.setButton2("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        alertDialog51.dismiss();                                                
                       }
                    });                         
                    alertDialog51.show(); 
             }
            else{
            LoginTask logintsk=new LoginTask();
            logintsk.execute();             
            }

        }
    });

    }
    private class LoginTask extends AsyncTask<Void, Void, Void> { 

        private final ProgressDialog dialog = new ProgressDialog(Rig_ParkingActivity.this);

        @Override
    protected void onPreExecute() { 

            this.dialog.setMessage("Loading ..."); 
            this.dialog.show(); 
        } 


    @Override
    protected Void doInBackground(final Void... unused) { 

      Log.i("Priyanka", "username"+username);
      Log.i("Priyanka", "password"+password);
      String auth=BusinessLogic_login.candidatelogin(username, password); 
      String userid=auth; 
        Log.i("priyanka", "auth"+auth);
        if(auth.equals("0")||(auth.equals("")))
        {
            Rig_ParkingActivity.this.runOnUiThread(new Runnable() {             
                public void run() {                 
                    final AlertDialog alertDialog51;                    
                  alertDialog51 = new AlertDialog.Builder(Rig_ParkingActivity.this).create();
                    alertDialog51.setMessage(Html
                       .fromHtml("<font color='#00beb4'><b>Enter correct Email or Password</b></font>"));                                                                                                       
                    alertDialog51.setButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                int which) {                            
                        alertDialog51.dismiss();    
                               }
                         });            
                    alertDialog51.setButton2("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        alertDialog51.dismiss();                                                
                       }
                    });                         
                    alertDialog51.show();               
                }
            });     
        }
        else {          

        Intent intnt=new Intent(getBaseContext(), Tab.class);
        startActivity(intnt);           

        }
        return null; // don't interact with the ui! 
    } 

    @Override
    protected void onPostExecute(Void result)  
    {  
            if (this.dialog.isShowing()) 
            { 
            this.dialog.dismiss(); 
            }
      } 
  }  
  }
4

1 回答 1

1
 private class LoginTask extends AsyncTask<Void, Void, Void> { 

        private final ProgressDialog dialog = new ProgressDialog(Rig_ParkingActivity.this);

        @Override
    protected void onPreExecute() { 

            this.dialog.setMessage("Loading ..."); 
            this.dialog.show(); 
        } 


    @Override
    protected Void doInBackground(final Void... unused) { 

      Log.i("Priyanka", "username"+username);
      Log.i("Priyanka", "password"+password);
      String auth=BusinessLogic_login.candidatelogin(username, password); 
      String userid=auth; 
        Log.i("priyanka", "auth"+auth);
        if(auth.equals("0")||(auth.equals("")))
        {
           flag=true;
            Rig_ParkingActivity.this.runOnUiThread(new Runnable() {             
                public void run() {                 
                    final AlertDialog alertDialog51;                    
                  alertDialog51 = new AlertDialog.Builder(Rig_ParkingActivity.this).create();
                    alertDialog51.setMessage(Html
                       .fromHtml("<font color='#00beb4'><b>Enter correct Email or Password</b></font>"));                                                                                                       
                    alertDialog51.setButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                int which) {                            
                        alertDialog51.dismiss();    
                               }
                         });            
                    alertDialog51.setButton2("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,
                                            int which) {
                                        alertDialog51.dismiss();                                                
                       }
                    });                         
                    alertDialog51.show();               
                }
            });     
        }

        return null; // don't interact with the ui! 
    } 

    @Override
    protected void onPostExecute(Void result)  
    {  
            if(!flag)
          {
           Intent intnt=new Intent(getBaseContext(), Tab.class);
          startActivity(intnt);
          }
            if (this.dialog.isShowing()) 
            { 
            this.dialog.dismiss(); 
            }
      } 
  }  

试试这段代码...有一个boolean名为flag的值并将其设置为 false。我刚刚使用它..你必须初始化它。

onPostExecute()将在 UI 线程中运行.. 如果您在doInBackground()方法中调用意图,它不会改变UIThread并且您看不到更改是我从您的代码中了解到的.. 检查这个

于 2012-10-20T06:40:12.803 回答