Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created March 16, 2015 08:01
Show Gist options
  • Save kunishi/a994ab80310fedbc7a46 to your computer and use it in GitHub Desktop.
Save kunishi/a994ab80310fedbc7a46 to your computer and use it in GitHub Desktop.
TestDialogFragment.java, fix version.
package com.example.time_circle;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
public class TestDialogFragment extends DialogFragment implements DialogInterface.OnClickListener{
private int year;
private int month;
private int day;
private LayoutInflater inflater;
private View content;
// LayoutInflater inflater = (LayoutInflater)(getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
// View content = inflater.inflate(R.layout.dialog_set,null);
public void onClick(DialogInterface dialog, int whichButton) {
if (whichButton == DialogInterface.BUTTON_POSITIVE){
DatePicker datePicker1 = (DatePicker)content.findViewById(R.id.datePicker1);
this.year = datePicker1.getYear();
this.month = datePicker1.getMonth() + 1;
this.day = datePicker1.getDayOfMonth();
EditText editText = (EditText)getActivity().findViewById(R.id.edittext2);
editText.setText(this.year +"/" + this.month +"/" + this.day);
}else if (whichButton == DialogInterface.BUTTON_NEGATIVE){
//No Action
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
inflater = (LayoutInflater)(getActivity().getSystemService(Add_content2.LAYOUT_INFLATER_SERVICE));
content = inflater.inflate(R.layout.dialog_set, null);
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
DialogInterface.OnClickListener MyInterface = new TestDialogFragment();
builder.setView(content);
//ダイアログのタイトル
builder.setMessage("日付の選択")
.setNegativeButton("Cancel", MyInterface)
.setPositiveButton("OK", MyInterface);
return builder.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment