I am trying to receive an integer in url.
This how i pass value from one activity to another:
private void displayCategoriesInformation(CategoriesModel categoriesModel) {
//get references to your views
TextView tvCategoryId = (TextView) findViewById(R.id.tvCategoryId);
final int categoryId = categoriesModel.getId();
//set values from your categoriesModel java object to textView
tvCategoryId.setText("Id : " + categoriesModel.getId());
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Categories.this, SubCategories.class);
intent.putExtra("parameter_name", categoryId);
startActivity(intent);
}
});
}
in SubCategory.class i receive it like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.row_subcategory);
Intent intent = getIntent();
int recivedId = intent.getIntExtra("parameter_name", 2);
TextView tvRecivedId = (TextView) findViewById(R.id.tvRecivedId);
tvRecivedId.setText("recivedId" + recivedId);
dialog = new ProgressDialog(this);
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.setMessage("Loading, please wait.....");
spinnerFood = (Spinner) findViewById(R.id.spinFood);
okButton = (Button) findViewById(R.id.bOk);
// spinner item select listener
spinnerFood.setOnItemSelectedListener(this);
new JSONTask().execute("http://146.185.178.83/resttest/subCategories");
}
now the value is stored in the variable recivedId which is 1 or 2 or 3 or 4
what i want to do is execute this JSONTask url like this
new JSONTask().execute("http://146.185.178.83/resttest/categories/recivedId/subCategories");
so the end url would look like this http://146.185.178.83/resttest/categories/1/subcategories/
how can i achieve this
String url = "http://146.185.178.83/resttest/categories/" + recivedId +"/subcategories/";
new JSONTask().execute(url);
Related
I am making the application in android studio, in my application i add the feature, if the user click on button second time, then the button is disable and save the state of button in sharedprefernce and if the user closed the app and again open the app then the save button state are shown(if the button is disabled then the disable button is show, else shows enable state ). I put many codes of sharedprefences in my code, but every time the null object reference occurs. My code is given below and I put the shared preferences code on this button but how?
java:
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
counrClick = counrClick + 1;
if (counrClick == 1) {
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("Url");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setTitle("" + "" + "");
request.setDescription("Downloading " + "" + "");
request.setVisibleInDownloadsUi(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/" + "filename");
refid = downloadManager.enqueue(request);
Log.e("OUT", "" + refid);
if (counrClick == 2) {
button.setEnabled(false);
}
}
}
});
Please refer the code below. and please remember you can use preference name ("MY_PREF") and key name ("DOWNLOAD_BUTTON_STATUS") to alter preference anywhere else in your application. You can even create a separate class for control all preferences in your application.
private SharedPreferences sharedPreferences;
private Button btn_download_one, btn_download_two, btn_download_three, btn_download_four;
private final String DOWNLOAD_BUTTON_STATUS_KEY_ONE = "DOWNLOAD_BUTTON_STATUS_ONE";
private final String DOWNLOAD_BUTTON_STATUS_KEY_TWO = "DOWNLOAD_BUTTON_STATUS_TWO";
private final String DOWNLOAD_BUTTON_STATUS_KEY_THREE = "DOWNLOAD_BUTTON_STATUS_THREE";
private final String DOWNLOAD_BUTTON_STATUS_KEY_FOUR = "DOWNLOAD_BUTTON_STATUS_FOUR";
private int clickCountOne = 0, clickCountTwo = 0, clickCountThree = 0, clickCountFour = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_download_one = findViewById(R.id.button1);
btn_download_two = findViewById(R.id.button2);
btn_download_three = findViewById(R.id.button3);
btn_download_four = findViewById(R.id.button4);
sharedPreferences = getSharedPreferences("MY_PREF", 0);
btn_download_one.setEnabled(getDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_ONE));
btn_download_two.setEnabled(getDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_TWO));
btn_download_three.setEnabled(getDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_THREE));
btn_download_four.setEnabled(getDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_FOUR));
btn_download_one.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//... some code
clickCountOne++;
if (clickCountOne == 2)
changeDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_ONE, false);
}
});
btn_download_two.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//... some code
clickCountTwo++;
if (clickCountTwo == 2)
changeDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_TWO, false);
}
});
btn_download_three.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//... some code
clickCountThree++;
if (clickCountThree == 2)
changeDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_THREE, false);
}
});
btn_download_four.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//... some code
clickCountFour++;
if (clickCountFour == 2)
changeDownloadButtonStatusPref(DOWNLOAD_BUTTON_STATUS_KEY_FOUR, false);
}
});
}
private void changeDownloadButtonStatusPref(String key, boolean status) {
sharedPreferences.edit().putBoolean(key, status).apply();
switch (key) {
case DOWNLOAD_BUTTON_STATUS_KEY_ONE:
btn_download_one.setEnabled(status);
clickCountOne = 0;
break;
case DOWNLOAD_BUTTON_STATUS_KEY_TWO:
btn_download_two.setEnabled(status);
clickCountTwo = 0;
break;
case DOWNLOAD_BUTTON_STATUS_KEY_THREE:
btn_download_three.setEnabled(status);
clickCountThree = 0;
break;
case DOWNLOAD_BUTTON_STATUS_KEY_FOUR:
btn_download_four.setEnabled(status);
clickCountFour = 0;
break;
}
}
private boolean getDownloadButtonStatusPref(String key) {
return sharedPreferences.getBoolean(key, true);
}
//Add this code on button click
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("enabled", "").apply();
//Add this code in OnCreate/OncreateView Method
String statusLocked1 = prefs.getString("enabled","");
if(statusLocked1.equals("enabled")){
//enable the button
}else{
//disbale the button
}
Try this it will disable button next time you run your activity if it was previously clicked twice;
Button button;
SharedPreferences preferences;
boolean firstclick = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// SharePrefs
preferences = getSharedPreferences("yourprefsname", 0);
firstclick = preferences.getBoolean("countclick", false);
button = findViewById(R.id.yourbutton);
//disables if it is clicked twice
if (!firstclick){
button.setEnabled(false);
}
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (firstclick) {
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("Url");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setTitle("" + "" + "");
request.setDescription("Downloading " + "" + "");
request.setVisibleInDownloadsUi(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/" + "filename");
refid = downloadManager.enqueue(request);
Log.e("OUT", "" + refid);
else{
//edit prefs
preferences.edit().putBoolean("countclick",firstclick).apply();
button.setEnabled(false);
}
}
}
});
}
Hello I'm Having a problem with my simple Android Application, it can't change the Text Colors in the other Activity which is displayActivity.java Here's my Code sample.
The problem is if the texts are both equal it will change into color greensuccess
but it did change into rederror
MainActivity.java
public class MainActivity extends AppCompatActivity {
public static final String xy = "ict402.germio.intent";
public static final String xz = "ict402.germio.intent";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send(View view){
EditText a = findViewById(R.id.a);
EditText b = findViewById(R.id.b);
String strx =(a.getText().toString());
String stry =(b.getText().toString());
if (strx.compareToIgnoreCase(stry) == 0)
{
// this line WILL print
Intent i = new Intent(this, displayActivity.class);
String t = ("Case Ignored \n VALUES ARE THE SAME CONGRATS!").toString();
i.putExtra(xy,t);
startActivity(i);
} else {
Intent i = new Intent(this, displayActivity.class);
String y = ("Case Ignored \n VALUES ARE NOT THE SAME SORRY!").toString();
i.putExtra(xz,y);
startActivity(i);
}
}
}
displayActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
Intent i = getIntent();
String message = i.getStringExtra(MainActivity.xy);
TextView t = findViewById(R.id.x);
t.setTextColor(getResources().getColor(R.color.success));
t.setText(message);
Intent o = getIntent();
String msg = o.getStringExtra(MainActivity.xz);
TextView q = findViewById(R.id.x);
q.setTextColor(getResources().getColor(R.color.error));
q.setText(msg);
}
}
There are so many things wrong. Here's a replacement:
public void send(View view) {
String editTextAContents = findViewById(R.id.a).getText().toString();
String editTextBContents = findViewById(R.id.b).getText().toString();
Intent intent = new Intent(this, DisplayActivity.class);
if (editTextAContents.equalsIgnoreCase(editTextBContents)) {
intent.putExtra("message", "Case Ignored \n VALUES ARE THE SAME CONGRATS");
intent.putExtra("error", false);
} else {
intent.putExtra("ict402.germio.intent", "Case Igored \n VALUES ARE NOT THE SAME SORRY!");
intent.putExtra("error", true);
}
startActivity(intent);
}
In DisplayActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
Intent intent = getIntent();
String message = intent.getStringExtra("message");
boolean hasError = intent.getBooleanExtra("error", false);
TextView textView = findViewById(R.id.x);
textView.setText(message);
if (hasError) {
textView.setTextColor(ContextCompat.getColor(this, R.color.error));
} else {
textView.setTextColor(ContextCompat.getColor(this, R.color.success));
}
}
When you populate an Intent's extras, they must have a different name.
When you declare variables, be more verbose instead of naming them x, y, z, a, b, c so they are more readable.
You're not using any conditional logic to determine what color to use.
You need to do something like this:
TextView t = findViewById(R.id.x);
String successMessage = getIntent().getStringExtra(MainActivity.xy);
String errorMessage = getIntent().getStringExtra(MainActivity.xz);
if(successMessage != null){
t.setTextColor(getResources().getColor(R.color.success));
t.setText(successMessage);
}else if(errorMessage != null){
t.setTextColor(getResources().getColor(R.color.error));
t.setText(errorMessage);
}
A better way of doing it is by sending a boolean through the intent to help you determine what color to set. Here is an example:
Intent i = new Intent(this, displayActivity.class);
if (strx.equalsIgnoreCase(stry)){
i.putExtra("message","Case Ignored \n VALUES ARE THE SAME CONGRATS!");
i.putExtra("success", true);
} else {
i.putExtra("message","Case Ignored \n VALUES ARE NOT THE SAME SORRY!");
i.putExtra("success", false);
}
startActivity(i);
And in the other activity, do this:
TextView t = findViewById(R.id.x);
Intent i = getIntent();
String message = getIntent().getStringExtra("message");
boolean success = getIntent().getBooleanExtra("success");
t.setText(message);
t.setTextColor(getResources().getColor(success ? R.color.success : R.color.error));
Please, do not mark this as duplicate if you are not sure
I have three spinners and a botton. When the botton is clicked, the program makes a calculation depending on the value of the three spinners. Then this value passes two another activity and it shows in an editText. Here is my code:
Main
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
capturarTexto();
}
private void capturarTexto() {
Button button_calc = (Button) findViewById(R.id.button_calc);
button_calc.setOnClickListener(get_edit_view_button_listener);
}
private Button.OnClickListener get_edit_view_button_listener = new Button.OnClickListener() {
public void onClick(View v) {
EditText edit_text = (EditText) findViewById(R.id.textBox1);
String edit_text_value = edit_text.getText().toString();
StringTokenizer st = new StringTokenizer(edit_text_value);
int num_words = st.countTokens();
Spinner espec = (Spinner) findViewById(R.id.espec);
String espec_value = espec.getSelectedItem().toString();
Spinner lengor = (Spinner) findViewById(R.id.lista_origen);
String lengor_value = lengor.getSelectedItem().toString();
Spinner lengdest = (Spinner) findViewById(R.id.lista_destino);
String lengdest_value = lengdest.getSelectedItem().toString();
double precio = 0;
if(espec_value .equals("Medicina")){
if (lengor_value .equals("ES") && lengdest_value .equals("EN")){
precio = num_words * 0.12;
}
if (lengor_value .equals("ES") && lengdest_value .equals("FR")){
precio = num_words * 0.12;
}
if (lengor_value .equals("ES") && lengdest_value .equals("DE")){
precio = num_words * 0.12;
}
Intent intent = new Intent(Main2Activity.this, Main3Activity.class);
intent.putExtra("precio",precio);
startActivity(intent);
}
};
}
Main2
public class Main3Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Intent intent=getIntent();
int precio =(int) intent.getExtras().getInt("precio");
TextView txtCambio = (TextView) findViewById(R.id.textView4);
txtCambio.setText("Precio Total: "+ precio + " €");
}
After testing it, the value passed in this line of code:
intent.putExtra("precio",precio)
is allways 0. But if I change it to this:
intent.putExtra("precio",num_words)
it passes correctly the total number of words. This makes me think that the script is not entering in the first if(espec_value .equals("Medicina")) and then, it is not making any calculation.
Does anyone have an idea of how to solve this problem?
Thank you for your time
You are sending Double value and accessing Integer value.
Change the line in Main3Activity.
double precio = intent.getExtras().getDouble("precio");
If you want to parse double value to int then add one more line
int p = (int) precio;
I've been trying to fix these two bugs for a while and I feel like it has to do with a fundamental misunderstanding of what happens when I open up a new activity. Basically the program is a task management program. It works fine when I add new tasks without modifying the category, and the database updates fine and the main page of the application updates as I add new tasks to display these new tasks.
However, I recently added functionality for an "add categories" button. The purpose of this button is to open up a new listactivity that allows users to add new categories of tasks. Every time I open this from the task editing activity and then press the back button to get back to the main page, all of the tasks in the database get cleared. Wondering if anyone can tell me what's going on and why the data is getting wiped out.
here's the relevant code snippet from the front page (the list view showing all of the tasks:
private RemindersDbAdapter mDbHelper;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
mDbHelper = new RemindersDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
private void fillData() {
Cursor remindersCursor = mDbHelper.fetchAllReminders();
startManagingCursor(remindersCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{RemindersDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter reminders =
new SimpleCursorAdapter(this, R.layout.reminder_row, remindersCursor, from, to);
setListAdapter(reminders);
}
Here's some of the code for my task editing view (the one calling the activity for the category listing):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new RemindersDbAdapter(this);
//mCatDbHelper = new CategoriesDbAdapter(this);
setContentView(R.layout.reminder_edit);
mCalendar = Calendar.getInstance();
mTitleText = (EditText) findViewById(R.id.title);
//mBodyText = (EditText) findViewById(R.id.body);
mDateButton = (Button) findViewById(R.id.reminder_date);
mTimeButton = (Button) findViewById(R.id.reminder_time);
mLowPriorityButton = (Button) findViewById(R.id.low_priority);
mMedPriorityButton = (Button) findViewById(R.id.med_priority);
mHighPriorityButton = (Button) findViewById(R.id.high_priority);
mManageCategories = (Button) findViewById(R.id.manage_categories);
mSchoolRadio = (RadioButton)findViewById(R.id.radio_schoolwork);
mFamilyRadio = (RadioButton)findViewById(R.id.radio_family);
mOtherRadio = (RadioButton)findViewById(R.id.radio_other);
mContext = this;
priority = "Low";
category = "Other";
mConfirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID)
: -1L;
registerButtonListenersAndSetDefaultText();
}
private void setRowIdFromIntent() {
if (mRowId == -1L) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(RemindersDbAdapter.KEY_ROWID)
: -1L;
}
}
#Override
protected void onPause() {
super.onPause();
mDbHelper.close();
}
#Override
protected void onResume() {
super.onResume();
mDbHelper.open();
setRowIdFromIntent();
//if(mRowId != -1L)
populateFields();
}
#Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case DATE_PICKER_DIALOG:
return showDatePicker();
case TIME_PICKER_DIALOG:
return showTimePicker();
}
return super.onCreateDialog(id);
}
private void populateFields() {
// Only populate the text boxes and change the calendar date
// if the row is not null from the database.
if (mRowId != -1L) {
Cursor reminder = mDbHelper.fetchReminder(mRowId);
startManagingCursor(reminder);
mTitleText.setText(reminder.getString(
reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_TITLE)));
category = reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_CATEGORY));
if(category.equals("School"))
mSchoolRadio.setChecked(true);
else if(category.equals("Family"))
mFamilyRadio.setChecked(true);
else
mOtherRadio.setChecked(true);
// Get the date from the database and format it for our use.
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
Date date = null;
try {
String dateString = reminder.getString(reminder.getColumnIndexOrThrow(RemindersDbAdapter.KEY_DATE_TIME));
date = dateTimeFormat.parse(dateString);
mCalendar.setTime(date);
} catch (ParseException e) {
Log.e("ReminderEditActivity", e.getMessage(), e);
}
} else {
// This is a new task - add defaults from preferences if set.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String defaultTitleKey = getString(R.string.pref_task_title_key);
String defaultTimeKey = getString(R.string.pref_default_time_from_now_key);
String defaultTitle = prefs.getString(defaultTitleKey, null);
String defaultTime = prefs.getString(defaultTimeKey, null);
if(defaultTitle != null)
mTitleText.setText(defaultTitle);
if(defaultTime != null)
mCalendar.add(Calendar.MINUTE, Integer.parseInt(defaultTime));
}
updateDateButtonText();
updateTimeButtonText();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if(mRowId == -1L)
mRowId = -1L;
outState.putLong(RemindersDbAdapter.KEY_ROWID, mRowId);
}
/*
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID)
: -1L;
}
*/
private void saveState() {
String title = mTitleText.getText().toString();
//String body = mBodyText.getText().toString();
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());
if (mRowId == -1L) {
long id = mDbHelper.createReminder(title, priority, category, reminderDateTime);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateReminder(mRowId, title, priority, category, reminderDateTime);
}
new ReminderManager(this).setReminder(mRowId, mCalendar);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
}
Here's the call (in the same class as the above code) to the new CategoryListActivity activity that's causing the problems:
mManageCategories.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(mContext, CategoryListActivity.class);
startActivity(i);
//populateFields();
}
});
I left out a lot of the less relevant code. Anyway like I said above... the main problem is that as soon as I start this new CategoryListActivity activity, the database and all the tasks get wiped out. weirdly, even if I restart the emulator the tasks don't get wiped as long as I don't start the CategoryListActivity. If anyone has any idea what's going on please help.
Andrew checkout this two links that will explain you everything about database integration.
http://www.devx.com/wireless/Article/40842/1954
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Hi I am creating a task reminder app. It works but I would like to create some sort of Toast validation. For example a user doesn't fill in the title and I'd like an toast saying "title needs to be filled in!" e.t.c
But I'm not sure how to do this.
I am using an EditText widget by the way.
This is one method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new RemindersDbAdapter(this);
setContentView(R.layout.reminder_edit);
mCalendar = Calendar.getInstance();
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
mDateButton = (Button) findViewById(R.id.reminder_date);
mTimeButton = (Button) findViewById(R.id.reminder_time);
mConfirmButton = (Button) findViewById(R.id.confirm);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(RemindersDbAdapter.KEY_ROWID)
: null;
registerButtonListenersAndSetDefaultText();
}
and another:
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());
if (mRowId == null) {
long id = mDbHelper.createReminder(title, body, reminderDateTime);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateReminder(mRowId, title, body, reminderDateTime);
}
new ReminderManager(this).setReminder(mRowId, mCalendar);
}
Thanks.
You should check inside your submit button's click listener whether all the necessary fields are filled in properly, and if not, just show up the toast:
Toast.makeText(getApplicationContext(), "Title needs to be filled in!",
Toast.LENGTH_SHORT).show();