我是新來的Android和我正在寫一個簡單的鬧鐘應用程序。當我輸入字符串像EditText這樣的「10:00,星期一」這個字符串將比較語法與定義的字符串,如果它真的會打開AlarmClock。但我不知道如何比較。你可以給我一個主意嗎?非常感謝。我的應用程序的界面和代碼下面將EditText中的文本與已定義的字符串進行比較?
1.My應用程序的界面https://dl.dropbox.com/u/40382482/Screenshot%20from%202012-10-25%2023%3A51%3A14.png
公共類MainActivity擴展活動{
@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);
}
請分享你迄今爲止編寫的代碼。 – 13hsoj
'if(myDefinedString.equals(myEditText.getText()。toString()){// do something}' – Squonk
哦,謝謝!我正在嘗試 –