-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddCoursetoCourseListTablePopup.java
65 lines (50 loc) · 2.29 KB
/
AddCoursetoCourseListTablePopup.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.scoresheet.discgolf;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import java.util.ArrayList;
/**
* Created by Joe Post on 5/25/2017.
* This serves as the pop-up for adding a new disc golf course to the list of available disc golf courses.
*/
public class AddCoursetoCourseListTablePopup extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Add New Disc Golf Course");
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.add_course_to_course_list_dialog, null);
final EditText DGcoursename = (EditText) view.findViewById(R.id.newDGcourseName);
builder.setView(view)
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
notifyToTarget(Activity.RESULT_OK, DGcoursename.getText().toString());
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
notifyToTarget(Activity.RESULT_CANCELED, "NO_NAME_ADDED");
}
});
return builder.create();
}
private void notifyToTarget(int code, String name) {
Fragment targetFragment = getTargetFragment();
if (targetFragment != null) {
Intent intent = new Intent();
ArrayList<String> name_list = new ArrayList<>();
name_list.add(0, name);
intent.putStringArrayListExtra("name_array", name_list);
targetFragment.onActivityResult(getTargetRequestCode(), code, intent);
}
}
}