0

i'm new with Android and i'm writing a simple alarm clock application.when i type the string into the EditText like this "10:00,Monday" this string will compare syntax with the defined string if true it'll turn on the AlarmClock. But i don't know how to compare. May you give me an idea? Thanks so much. My app's interface and code below

1.My app's interface https://dl.dropbox.com/u/40382482/Screenshot%20from%202012-10-25%2023%3A51%3A14.png

public class MainActivity extends Activity {

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* Calendar cal = Calendar.getInstance(); SimpleDateFormat date = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat time = new SimpleDateFormat("hh:mm:ss"); final TextView labelDate = (TextView) findViewById(R.id.lblDate); final TextView lableTime = (TextView) findViewById(R.id.lblTime); labelDate.setText(date.format(cal.getTime())); lableTime.setText(time.format(cal.getTime()));*/ final ArrayList<String> setAlarm = new ArrayList<String>(); //nhap noi dung vao edit text final EditText alarmEnter = (EditText) findViewById(R.id.setting); final Button button = (Button) findViewById(R.id.Okay); OnClickListener add = new OnClickListener() { public void onClick(View v) { if(alarmEnter.getText().toString().equals("")) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("Info Missing"); builder.setMessage("Please Enter All Information"); builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() { public void onClick(DialogInterface diablog, int which) { } } ); builder.show(); } else { //compare string in EditText and defined string? } } }; button.setOnClickListener(add); } 
3
  • 1
    Please share the code you have written so far. Commented Oct 25, 2012 at 16:46
  • 1
    if (myDefinedString.equals(myEditText.getText().toString()) { // do something } Commented Oct 25, 2012 at 16:49
  • oh thank you! i'm trying Commented Oct 25, 2012 at 17:01

2 Answers 2

5

To compare one string with another, use:

if(strText.equals("myString")){ // strText is the string from the edit text, myString is the string // you are comparing it to // do something }else{ // do something else } 

This will return a boolean.

Sign up to request clarification or add additional context in comments.

Comments

3

if (myEditText.getText().toString().equals(myString)) { ... }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.