2011-06-20 12 views
0

我正在使用Android應用程序。 該應用程序有一系列的表單,我想確認用戶在進入下一組表單之前填寫這些表單。什麼是最好的方式來做到這一點?不完整的表單提示 - Android

public void goOne() 
{ 
    setContentView(R.layout.main); 
    next = (Button) findViewById(R.id.next); 
    logo = (Button) findViewById(R.id.logo); 
    cityText = (EditText)findViewById(R.id.city); 
    about = (Button) findViewById(R.id.aboutus); 

    about.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      goAboutUs(); 
     } 
    }); 
    logo.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      goOne(); 
     } 
    }); 

    next.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) 
     { 
      city = (String)cityText.getText().toString(); 
      if(stateLoc.equalsIgnoreCase("international")) 
      { 
       location = ""; 
       isInternational = 1; 
      }else 
      { 
       location = city; 
      } 
      if(cityText.getText().equals("") && stateLoc.equalsIgnoreCase("U.S.A")) 
      { 
      new AlertDialog.Builder(Tents.this) 
      .setTitle("Error") 
      .setMessage("Enter ZIP Code, or choice International ") 
      .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 
        goOne(); 
       } 
      }).show(); 
      }else{ 
      goTwo(); 
      } 
     } 
    }); 

那是我的代碼。我正在嘗試驗證cityText文本框。如果它沒有任何東西,並且stateLoc被設置爲USA,那麼彈出警報,如果沒有,那麼goTwo()

回答

0

如果形式是普通文本的意見,你可以使用下面的代碼:

myTextView.getText().trim().isEmpty()將返回的TextView是否爲空或不

0

你不是真的給我們提供了很多信息,但是你最終是否提交了表格上的信息?你不能檢查,看看用戶是否留下空白的信息?

+0

我給在問題領域的一些詳細信息 – Zaask

相關問題