먼저 onClick 메소드 안을 디버깅 해보세요. 그리고 아래가 의심됩니다.
자바에서 String 비교는 equals입니다.
private String date = m_Date.getText().toString(); // date변수는 lower case로 사용하세요!!! 클래스이름과 중복됩니다.
if(date==null || date.equlas("")) {
...
}
참고로 코드를 읽기 편하게 정리하시길 추천드려요. 변수이름들도 그렇고 읽기에 좀 어지럽네요. 아래를 참고하세요.
public class EditActivity extends AppCompatActivity{
ListView scrollList; //자바 명명규칙을 따르세요. 변수명에 underscore(_)는 사용하지 않습니다.
EditText timeSheetDateEdit';
EditText startDateEdit;
EditText endDateEdit;
EditText reasonEdit;
Button yesButton;
Button noButton;
// 마찬가지로, 명확한 이름을 주세요.
Button homeButton;
Button salaryButton;
Button schduleButton;
Button departmentButton;
DBHelper dbHelper;
SQLiteDatabase db;
private DBHelper getDBHelper() {
if (dbHelper == null) {
dbHelper = new DBHelper(this);
}
return dbHelper;
}
private SQLiteDatabase getDB() {
if (db == null) {
db = getDBHelper().getWritableDatabase();
}
return db;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_edit);
bindViews();
fetchTimesheet();
}
private void bindViews() {
// XML의 id도 변수이름과 같이 명확하게 주세요.
scrollList = (ListView)findViewById(R.id.me_ScrollList);
timeSheetDateEdit = (EditText)findViewById(R.id.me_Date);
startDateEdit = (EditText)findViewById(R.id.me_Start);
endDateEdit = (EditText)findViewById(R.id.me_End);
reasonEdit = (EditText)findViewById(R.id.me_Reason);
yesButton = (Button)findViewById(R.id.me_Yes);
noButton = (Button)findViewById(R.id.me_No);
// View의 이벤트 핸들러는 개별적으로 사용하는 것이 코드를 읽거나 유지보수하는데 더 쉽습니다.
yesButton.setOnClickListener { yesButtonClicked() }
noButton.setOnClickListener { noButtonClicked() }
homeButton = (Button)findViewById(R.id.tap1);
salaryButton = (Button)findViewById(R.id.tap2);
schduleButton = (Button)findViewById(R.id.tap3);
departmentButton = (Button)findViewById(R.id.tap4);
homeButton.setOnClickListener { navigateHome(); }
salaryButton.setOnClickListener { navigateToSalary(); }
schduleButton.setOnClickListener { navigateToSchedule(); }
departmentButton.setOnClickListener{ navigateToDepartment(); }
}
// navigation을 하는 코드는 별도로 관리 클래스를 만들어 사용하는 것이 좋습니다.
// eg. screensNavigator.goHome()
private void navigateHome() {
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
}
private void navigateToSalary() {
Intent intent2 = new Intent(this, MainActivity.class);
startActivity(intent2);
}
private void navigateToSchedule() {
Intent intent3 = new Intent(this, MainActivity.class);
startActivity(intent3);
}
private void navigateToDepartment() {
Intent intent4 = new Intent(this, DepartmentActivity.class);
startActivity(intent4);
}
// 폼 유효성 체크를 하는 코드도 별도의 클래스 분리할 수 있다면 더 좋습니다.
@Nullable
private FieldError checkUserInputError() {
List<Pair<String, Int>> inputFields = Arrays.asList(
new Pair(TextViewUtiils.text(timeSheetDateEdit), R.string.timesheet_date_label),
new Pair(TextViewUtiils.text(startDateEdit), R.string.start_date_label),
new Pair(TextViewUtiils.text(endDateEdit), R.string.end_date_label),
new Pair(TextViewUtiils.text(reasonEdit), R.string.reason_label)
);
for (Pair<String, Int> fieldInfo : inputFields) {
FieldError error = checkFieldError(fieldInf);
if (error != null) {
return error;
}
}
return null;
}
@Nullable
private FieldError checkFieldError(Pair<String, Int> fieldInfo) {
return input.isEmpty(fieldInfo.getFirst()) ?: new FieldError(fieldInfo.getSecond()) : null
}
private void yesButtonClicked() {
FieldError error = checkUserInputError();
if (error != null) {
showInputErrorMessage(error.getString(this));
return;
}
updateTimesheet();
}
private void showInputErrorMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
private void updateTimesheet() {
getDB().execSQL("UPDATE cworktbl SET wChange = ?, wChangeDate = ?, wChangeCause = ?, wNewGoTime = ?, wNewOffTime = ? WHERE wDate = ?;",
new String[] {"1", Date, Reason, Start, End, Date});
getDB()..close();
finish();
}
private void noButtonClicked() {
...
}
public void fetchTimesheet(){
try{
Cursor cursor = getDB().rawQuery("SELECT wGoTime, wOffTime FROM cworktbl", null);
MainAdapter adapter = new MainAdapter();
if(cursor.getCount()!=0){
//조회온 데이터가 있을때 내부 수행
while(cursor.moveToNext()) {
adapter.addItemList(cursor.getString(0), cursor.getString(1));
}
}
me_ScrollList.setAdapter(adapter);
adapter.notifyDataSetChanged();
}catch(Exception e){e.printStackTrace();}
}
}
// 필드 에러정보를 담는 클래스. 메세지는 가급적이면 하드코딩하지 마시고 String resource 를 사용하세요.
class FieldError {
@StringRes private final int fieldNameRes;
@StringRes private final int messageRes; // String resource에 %1$s가 들어가 있어서 포맷팅이 되도록.
public FieldError(int fieldNameRes, int messageRes) {
this.fieldNameRes = fieldNameRes;
this.messageRes = messageRes;
}
public FieldError(int fieldNameRes) {
this(fieldNameRes, R.string.field_required_message);
}
public String getMessage(context Context) {
String fieldName = context.getResources().getString(fieldNameRes);
return context.getResources().getString(messageRes, fieldName);
}
}
public classTextViewUtils {
public static String text(TextView textView, defaultValue: String) {
val s = textView.getText().toString();
return s == null ? "" : s;
}
public static String text(TextView textView) {
return text(textView, "");
}
}
아직 수정할 부분이 많이 남아 있지만 전체 구조를 잡는데는 도움이 되실 거예요.