-2

radioButton1.getText().toString().equals("")下面的代码中的错误是什么?

我想强制用户填写此字段,如果他将该字段留空,则发送一条填写必填字段的消息。我该怎么做呢?

page1.setOnClickListener(new View.OnClickListener() { 

public void onClick(View v) { 
    if(radioButton1.getText().toString().equals("")||radioButton2.getText().toString().equals("")||radioButton3.getText().toString().equals("")||radioButton4.getText().toString().equals("")
||petn.getText().toString().equals("")||breed.getText().toString().equals("")||color.getText().toString().equals("")||alergic.getText().toString().equals("")||ath_locat.getText().toString().equals("")||d_condi.getText().toString().equals("")||weight1.getText().toString().equals("")
    )
    { 
    Log.e("onclick", ",pd"); 
    Toast msg = Toast.makeText( 
    My2Activity.this,"Please fill the * required field",Toast.LENGTH_LONG); 
    msg.show(); 
     } 
    else{ 
    PostData(); 
    Intent d = new Intent(getApplicationContext(), 
    My1Activity.class); 
    startActivity(d); 
    } 
    } 
    });
4

2 回答 2

2
if(radioButton1.isChecked())
{

}
else
{

}

您想将 OnCheckedChangeListener 设置为单选按钮

radioButton1.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) 
{

}
}
于 2012-09-21T12:27:31.163 回答
0

我认为你应该使用

radioButton1.isChecked()
于 2012-09-21T12:25:40.470 回答