/**
*
*/
package net.tasksnow.view.task;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import net.tasksnow.R;
/**
* @author Benjamin
* I suggest to take a normal view with Dialog-Theme to use our layout
*/
public class LabelsDialogFragment extends DialogFragment {
String[] labelStrings;
public interface NoticeDialogListener {
public void onLabelClick(String label);
}
NoticeDialogListener mListener;
// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
// Instantiate the NoticeDialogListener so we can send events to the host
mListener = (NoticeDialogListener) activity;
}
catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
labelStrings = getArguments().getStringArray("labels");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// builder.setTitle("Labels");
//Use own labels header
LayoutInflater inflater = (LayoutInflater) getActivity().getActionBar().getThemedContext().getSystemService("layout_inflater");
final View labelDialogView = inflater.inflate(R.layout.label_dialog_header, null);
builder.setCustomTitle(labelDialogView);
builder.setItems(labelStrings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mListener.onLabelClick(labelStrings[which]);
}
});
return builder.create();
}
}