I'd like to show a toast message when entering a number less than 180 , I'm a beginner but I need some help , so i want to show a specific message when entering a number less than 180 , so what to write in the if method ?
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();
}
}
and this is the xml code :
<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"/>
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();
Compare the text with 180 by:
if(Integer.valueOf(ed1.getText().toString())<180)
Toast.makeText(getBaseContext(),"Message",Tosat.LENGTH_LONG).show();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.