2011-06-16 47 views
0

我創建一個登錄應用 錯誤的登錄腳本是確定它的返回真假我的意圖腳本總是顯示

如果響應返回true或1,我想讓它去另一個活動所謂inputBarcode,表現出對我的原意錯誤的日食,我不知道該怎麼辦

我不知道製作意圖

這是我的全部代碼的另一變化是什麼,目的是我想要調用if(res.equals(「1」))後的底部{:

package com.nigmagrid.go; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.view.View.OnClickListener; 
    import android.widget.AdapterView; 
    //import android.widget.AdapterView.OnItemSelectedListener; 
    import android.widget.ArrayAdapter; 
    import android.widget.Button; 
    import android.widget.EditText; 
    import android.widget.Spinner; 
    import android.widget.TextView; 
    import android.widget.Toast; 

    import java.util.ArrayList; 
    import org.apache.http.NameValuePair; 
    import org.apache.http.message.BasicNameValuePair; 

    public class login extends Activity { 

     String lokasiTugas; 

     boolean status_npp; 
     boolean status_password; 
     boolean status_lokasi; 

     Button button; 
     EditText usernameEditText, passwordEditText; 
     TextView error; 
     Spinner lokasiSpinner; 

     final int minNPP = 3; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle icicle) { 
      super.onCreate(icicle); 

      setContentView(R.layout.login); 

      final Button button = (Button) findViewById(R.id.login_button); 
      final EditText usernameEditText = (EditText) findViewById(R.id.login_npp); 
      final EditText passwordEditText = (EditText) findViewById(R.id.login_password); 
      final Spinner lokasiSpinner = (Spinner) findViewById(R.id.spinner1); 
      final TextView error = (TextView) findViewById(R.id.login_status); 

      ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
        this, R.array.lokasi_array, android.R.layout.simple_spinner_item); 
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

      lokasiSpinner.setAdapter(adapter); 

      lokasiSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
       @Override 
       public void onItemSelected(AdapterView adapter, View v, int i, long lng) { 
        //Toast.makeText(getApplicationContext(), adapter.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show(); 
        lokasiTugas = adapter.getItemAtPosition(i).toString(); 
       } 

       @Override 
       public void onNothingSelected(AdapterView arg0) { 
        //do something else 
       } 
      }); 

      button.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) { 

        error.setText("Menghubungkan ke server..."); 

        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 
        postParameters.add(new BasicNameValuePair("username", usernameEditText.getText().toString())); 
        postParameters.add(new BasicNameValuePair("password", passwordEditText.getText().toString())); 

        String response = null; 

        String sNPP = usernameEditText.getText().toString().replace(" ", ""); 
        String sPassword = passwordEditText.getText().toString(); 

        // validasi NPP 
        if(sNPP.length()<=minNPP){ 
         usernameEditText.setError("NPP minimal "+minNPP+" angka"); 
         status_npp = false; 
        }else{ 
         status_npp = true; 
         //Toast.makeText(getApplicationContext(), "NPP Anda : "+sNPP, Toast.LENGTH_SHORT).show(); 
        } 

        // validasi Password 
        if(sPassword.length()<1){ 
         passwordEditText.setError("Kata sandi diperlukan"); 
         status_password = false; 
        }else{ 
         status_password = true; 
        } 

        //validasi lokasiTugas 
        if(lokasiTugas.equals("Pilih Lokasi")){ 
         Toast.makeText(getApplicationContext(), "Lokasi Tugas diperlukan", Toast.LENGTH_SHORT).show(); 
         status_lokasi = false; 
        }else{ 
         status_lokasi = true; 
        } 

        // pengecekan akhir 
        if(status_npp == true && status_password == true && status_lokasi == true){ 

         //Toast.makeText(getApplicationContext(), "NPP Anda : "+sNPP+"\nLokasi : "+lokasiTugas, Toast.LENGTH_SHORT).show(); 


         //fungsi login disini :D 

         try{ 
          // variabel cek-nya ganti 
          String cek = "http://almezuflash.zxq.net/kspt-android/ceklogin.php"; 
          response = CustomHttpClient.excecuteHttpPost(cek, postParameters); 
          String res = response.toString(); 
          res = res.replaceAll("\\s", ""); 

          Toast.makeText(getApplicationContext(), res, Toast.LENGTH_SHORT).show(); 

          if(res.equals("1")){ 
           error.setText("Login sukses"); 
           Toast.makeText(getApplicationContext(), "Login Sukses", Toast.LENGTH_SHORT).show(); 
// i want to make Intent but eclipse says error, and i don't know what to do 

           Intent doBarcode = new Intent(parent, inputBarcode.class); 
           startActivity(doBarcode); 

          }else{ 
           error.setText("Login gagal"); 
           //Toast.makeText(getApplicationContext(), "Login Gagal", Toast.LENGTH_SHORT).show(); 
          } 

         }catch (Exception e){ 
          //error.setText(e.toString()); 
          error.setText("Terjadi kesalahan, silahkan periksa koneksi internet anda"); 
         } 

        }else{ 
         //Toast.makeText(getApplicationContext(), "Otorisasi Gagal", Toast.LENGTH_SHORT).show(); 
         status_npp = false; 
         status_password = false; 
         status_lokasi = false; 
         error.setText("Login gagal, silahkan periksa kembali"); 
        } 

       } 
      }); 

     } 
    } 

對不起我的英文不好,我從印尼是供參考:d

回答

0

你確定到inputBarCode活動添加到您的AndroidManifiest?如果你沒有,那麼這會給運行時錯誤。如果那沒有問題,則可能改變

Intent doBarcode = new Intent(parent, inputBarcode.class); 

Intent doBarcode = new Intent(this, inputBarcode.class); 

將解決你的問題。我不熟悉正在使用的父變量。

我希望有幫助。

0

嘗試,而不是

Intent doBarcode = new Intent(parent, inputBarcode.class); 

使用此代碼:

Intent doBarcode = new Intent(login.this, inputBarcode.class);