2
if(productItem.ProductName.equals(""))
{
Toast.makeText(getApplicationContext(), "Please Enter the Product Name...",
                        Toast.LENGTH_LONG).show();

                ((InputMethodManager) MainFormActivity.this
                        .getSystemService(Context.INPUT_METHOD_SERVICE))
                        .showSoftInput(pName, 0);
            }

这段代码对我不起作用,我想每次点击保存按钮时都应该验证缺失的字段,如果缺少的光标应该出现在缺失的字段中。

4

2 回答 2

0

我在这里可能错了,但productItem.ProductName在我看来,它就像一个具有您创建的属性的类。如果要检查 an 中的文本,EditText则应将 if 语句更改为以下内容:

EditText txt = (EditText)findViewById(R.Id.textID);
if(txt.GetText().Equals("")){
  //do something
{

这样,您将EditText在单击按钮时检查布局中的 是否为空。

于 2013-04-03T08:02:26.560 回答
0

试试这个验证它会将编辑文本上的红色气球显示为空白 if(edittext.lenth()<=0) edittext.setError(error msg);

于 2013-04-03T08:02:30.930 回答