-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(); 
            }
      } 
  }  

このコードを試してください... flagbooleanという値を設定し、falseに設定します。私はちょうどそれを使用しました..あなたはそれを初期化する必要があります。

onPostExecute()UIスレッドで実行されます。doInBackground()メソッドでintentを呼び出すと、変更されUIThreadず、変更がコードからわかったことがわかりません。これを確認してください。

于 2012-10-20T06:40:12.803 に答える