我正在创建一个简单的应用程序。我试图将数据存储在SQLite数据库中。我没有错。但是,我觉得我已经搞乱了内部类的括号和嵌套。我有3个按钮 - 日期选择器,时间选择器和创建帐户。用户界面工作正常。我检查了db代码(通过创建其他项目),这也正常。但是,在此应用程序中,点击创建帐户后,它不会显示消息 - '数据已成功保存'或者如果我把田地空置,那么它也没有显示消息 - "字段空置"。所以,我觉得我对这个特定的代码做了一些错误。我正在关注在线教程。您可以为我检查并修改代码吗?
TabFragment1.java
public class TabFragment1 extends Fragment {
TextView textViewTitle;
EditText editTextName;
EditText editTextBuy;
EditText editTextHome;
EditText editTextStore;
EditText editTextAddress;
EditText editTextPhone;
EditText editTextDate;
Button buttonCreateAccount;
Button btnDatePicker, btnTimePicker;
EditText txtDate, txtTime;
private int mYear, mMonth, mDay, mHour, mMinute;
DataBaseAdapter dataBaseAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_1, container, false);
/*
get Instance of Database Adapter
dataBaseAdapter= new DataBaseAdapter(getContext());
*/
dataBaseAdapter = new DataBaseAdapter(getActivity());
dataBaseAdapter = dataBaseAdapter.open();
// Get Refferences of Views
textViewTitle = (TextView) view.findViewById(R.id.textViewTitle);
editTextName = (EditText) view.findViewById(R.id.editTextName);
editTextBuy = (EditText)view.findViewById(R.id.editTextBuy);
editTextHome = (EditText) view.findViewById(R.id.editTextHome);
editTextStore = (EditText) view.findViewById(R.id.editTextStore);
editTextAddress = (EditText)view.findViewById(R.id.editTextAddress);
editTextPhone = (EditText) view.findViewById(R.id.editTextPhone);
editTextDate = (EditText) view.findViewById(R.id.editTextDate);
buttonCreateAccount = (Button) view.findViewById(R.id.buttonCreateAccount);
btnDatePicker = (Button) view.findViewById(R.id.btn_date);
btnTimePicker = (Button) view.findViewById(R.id.btn_time);
txtDate = (EditText) view.findViewById(R.id.in_date);
txtTime = (EditText) view.findViewById(R.id.in_time);
/* btnDatePicker.setOnClickListener(this);
btnTimePicker.setOnClickListener(this);
buttonCreateAccount.setOnClickListener(this);*/
btnDatePicker.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
}
});
btnTimePicker.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Get Current Time
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
// Launch Time Picker Dialog
TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
txtTime.setText(hourOfDay + ":" + minute);
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
});
buttonCreateAccount.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String name = editTextMedicineName.getText().toString();
String buy = editTextQuantityToBuy.getText().toString();
String lHome = editTextLeftAtHome.getText().toString();
String mStore = editTextMedicineStore.getText().toString();
String mAdd = editTextMedStoreAddress.getText().toString();
String phone = editTextPhone.getText().toString();
String date = editTextDate.getText().toString();
// check if any of the fields are vaccant
if (name.equals("") || buy.equals("") || lHome.equals("") || mStore.equals("") || mAdd.equals("") || phone.equals("") || date.equals("")) {
Toast.makeText(getContext(), "Field Vacant", Toast.LENGTH_LONG).show();
return;
}
else {
// Save the Data in Database
dataBaseAdapter.insertEntry(name, buy, lHome, mStore, mAdd, phone, date);
Toast.makeText(getContext(), "Reminder Successfully Created", Toast.LENGTH_LONG).show();
}
}
});
return view;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
dataBaseAdapter.close();
}
}