2013-04-06 3 views
0

Я хочу, чтобы ваша помощь во что-то Я ищу, чтобы поместить код, который может проверить, пустыми ли текстовые поля или нет , если текстовые поля пусты. Я хочу показать текстовый messg, говорящий, что Данные являются неполными и, если не мы продолжаем отросток проблему, что я не зная, где я должен написать, если условие, чтобы проверить, текстовые поля пусты или не пожалуйста, проверьте мой код:проверить текстовые поля, если написано андроид

public class register extends Activity { 

private ProgressDialog pDialog; 

JSONParser jsonParser = new JSONParser(); 
EditText inputName; 
EditText inputUser; 
EditText inputPass; 
EditText inputAge; 
EditText inputBloodType; 

// url to create new product 
private static String url_create_product = "http://10.0.2.2/blood_needed/create_product.php" ; 

// JSON Node names 
private static final String TAG_SUCCESS = "success"; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.register); 
    inputName = (EditText) findViewById(R.id.editText1); 
    inputUser = (EditText) findViewById(R.id.editText5); 
    inputPass = (EditText) findViewById(R.id.editText3); 
    inputAge = (EditText) findViewById(R.id.editText2); 
    inputBloodType = (EditText) findViewById(R.id.editText4); 

    // Create button 
    Button btnRegister = (Button) findViewById(R.id.Button01); 

    // button click event 
    btnRegister.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      // creating new product in background thread 
      new CreateNewProduct().execute(); 
     } 
    });} 

class CreateNewProduct extends AsyncTask<String, String, String> { 

/** 
* Before starting background thread Show Progress Dialog 
* */ 
@Override 
protected void onPreExecute() { 
    super.onPreExecute(); 
    pDialog = new ProgressDialog(register.this); 
    pDialog.setMessage("Regestering.."); 
    pDialog.setIndeterminate(false); 
    pDialog.setCancelable(true); 
    pDialog.show(); 
} 



protected String doInBackground(String... args) { 
    String name = inputName.getText().toString(); 
    String user = inputUser.getText().toString(); 
    String pass = inputPass.getText().toString(); 
    String age = inputAge.getText().toString(); 
    String bloodtype = inputBloodType.getText().toString(); 


    // Building Parameters 
    List<NameValuePair> params = new ArrayList<NameValuePair>(); 
    params.add(new BasicNameValuePair("name", name)); 
    params.add(new BasicNameValuePair("username", user)); 
    params.add(new BasicNameValuePair("password", pass)); 
    params.add(new BasicNameValuePair("age", age)); 
    params.add(new BasicNameValuePair("bloodtype", bloodtype)); 

    // getting JSON Object 
    // Note that create product url accepts POST method 
    JSONObject json = jsonParser.makeHttpRequest(url_create_product, 
      "POST", params); 

    // check log cat fro response 
    Log.d("Create Response", json.toString()); 

    // check for success tag 
    try { 
     int success = json.getInt(TAG_SUCCESS); 

     if (success == 1) { 
      // successfully created product 
      // closing this screen 
      finish(); 
     } else { 
      // failed to create product 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

    return null; 
} 

/** 
* After completing background task Dismiss the progress dialog 
* **/ 
protected void onPostExecute(String file_url) { 
    Toast.makeText(getBaseContext(), "Succes!", Toast.LENGTH_SHORT).show(); 

    // dismiss the dialog once done 
    pDialog.dismiss(); 
}} 

ответ

1

Положи в onClick()

btnRegister.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      // creating new product in background thread 
      String name = inputName.getText().toString(); 
    String user = inputUser.getText().toString(); 
    String pass = inputPass.getText().toString(); 
    String age = inputAge.getText().toString(); 
    String bloodtype = inputBloodType.getText().toString(); 
     if(user.equals("") || pass.equals("") || age.equals("") || bloodtype.equals("") || name.equals("")){ 
      // add message here 
      }else{ 
      new CreateNewProduct().execute(); 
      } 
     } 
    });} 
+0

большое спасибо человек – Charbel

Смежные вопросы