Hello, I am a new developer and am making my first app which will be open source after I finish it.
How do you make a notification apply to all dynamically created objects rather than the last one in a linear layout?
I have created 2 methods, one called CreateDialog(); and the other called ShowNotification();
Each have their own unique buttons with onclicklisteners.
The CreateDialog method creates an editable dialog where if you press the "ok" button, a Checkbox appears with whatever you typed into the edit text.
The ShowNotification method is suppose to alert the user that in the event a dynamically created Checkbox is unchecked; a notification will appear in the status bar.
However, my program only works with the last dynamically generated Checkbox and fails to apply to all the others. How do I resolve this? Thank you for your time.
public void CreateDialog(){
> AlertDialog.Builder alert = new AlertDialog.Builder(ObjectView.getContext());
> alert.setTitle("Generate Checkbox?");
> alert.setMessage("Enter name below");
> final EditText input = new EditText(ObjectView.getContext());
> alert.setView(input);
> alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog, int whichButton) {
> newcheckbox = new CheckBox(ObjectView.getContext());
> newcheckbox.setText(input.getText().toString());
> layout.addView(newcheckbox);
>
> }
> });
> alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog, int whichButton) {
> // Cancelled.
> }
> });
> alert.show();
> }
>
> public void ShowNotification(){
> if(newcheckbox ==null){
>
> }
> else if (newcheckbox.isChecked()){
> }
>
> else {
>
> NotificationCompat.Builder mBuilder =
> new NotificationCompat.Builder(getActivity())
> .setSmallIcon(android.R.drawable.stat_notify_more)
> .setContentTitle("Items missing")
> .setContentText("One or more items are missing");
> int ID_Notify = 01;
> getActivity();
> // Gets an instance of the NotificationManager service
> NotificationManager managenote = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
>
> managenote.notify(ID_Notify, mBuilder.build());
>
> }
> }