我想在输入少于180的数字时显示祝酒消息,我是初学者,但我需要一些帮助,所以我想在输入少于180的数字时显示特定消息,那么该怎么做写入if方法?
public class MainActivity extends Activity {
EditText ed1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = (EditText)findViewById(R.id.editText1);
}
public void mansaf (View v)
{
if (){
Toast.makeText(MainActivity.this, "Message1", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(MainActivity.this, "Message2 ", Toast.LENGTH_LONG).show();
}
}
这是xml代码:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:hint="ما السرعة التي تقود بها عادة ؟" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ما مستوى قيادتي ؟"
android:onClick="mansaf"/>
答案 0 :(得分:1)
if (Integer.valueof( ed1.getText().toString)<180))
Toast.makeText(MainActivity.this, "Message1", Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this, "Message2 ", Toast.LENGTH_LONG).show();
答案 1 :(得分:0)
将文本与180比较:
if(Integer.valueOf(ed1.getText().toString())<180)
Toast.makeText(getBaseContext(),"Message",Tosat.LENGTH_LONG).show();