2012-10-20 84 views
-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(); 
      } 
     } 
    } 
    } 
+2

@VincenzoSanchez:我不觉得如此... –

+2

Priyanka请编辑您的问题,格式代码。阅读你的代码很困难。 –

+0

你想要登录什么系统? – nhahtdh

回答

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值称为标志,并将其设置为false。我刚刚使用它..你必须初始化它。

onPostExecute()将在UI线程中运行。如果你打电话的意图在doInBackground()方法,它并不在UIThread改变,你不能看到的变化是我得到了你的代码知道..检查这个

+1

你能解释一下你对OP的代码做了什么吗?什么改变,使其工作? – Eric

+0

BobbeHoddi可以将意图放在后期执行方法上,我认为他是正确的 – Jeetu

相关问题