Created
August 15, 2014 15:45
-
-
Save xxnjdlys/850bc66521b7c7543956 to your computer and use it in GitHub Desktop.
pass param into fragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wukongtv.wkremote.client; | |
import android.app.Dialog; | |
import android.graphics.drawable.ColorDrawable; | |
import android.os.Bundle; | |
import android.support.v4.app.DialogFragment; | |
import android.text.TextUtils; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.Window; | |
import android.widget.Button; | |
import android.widget.TextView; | |
/** | |
* DeviceDialog | |
* Created by zhangge on 14-2-14. | |
*/ | |
public class ConfirmDialog extends DialogFragment implements View.OnClickListener { | |
private static final String TITLE = "title"; | |
private static final String MESSAGE = "message"; | |
private static final String YES_BTN_TEXT = "yes_btn_text"; | |
private static final String CANCEL_BTN_TEXT = "cancel_btn_text"; | |
private static final String EXIT_BTN_TEXT = "exit_btn_text"; | |
Button btnOK, btnCancel, btnOther; | |
TextView tvTitle, tvInfo; | |
OnDialogActionListener mDialogListener; | |
public static ConfirmDialog newInstance(String title, String message,String yesBtnText, String cancelBtnText ) { | |
ConfirmDialog fragment = new ConfirmDialog(); | |
Bundle args = new Bundle(); | |
args.putString(TITLE,title); | |
args.putString(MESSAGE,message); | |
args.putString(YES_BTN_TEXT,yesBtnText); | |
args.putString(CANCEL_BTN_TEXT,cancelBtnText); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
public static ConfirmDialog newInstance(String title, String message,String yesBtnText, String cancelBtnText ,String exitBtnText) { | |
ConfirmDialog fragment = new ConfirmDialog(); | |
Bundle args = new Bundle(); | |
args.putString(TITLE,title); | |
args.putString(MESSAGE,message); | |
args.putString(YES_BTN_TEXT,yesBtnText); | |
args.putString(CANCEL_BTN_TEXT,cancelBtnText); | |
args.putString(EXIT_BTN_TEXT,exitBtnText); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
public ConfirmDialog() {} | |
public interface OnDialogActionListener{ | |
public void onOKClick(); | |
public void onCancel(); | |
public void onOther(); | |
} | |
public void setOnDialogBtnClickListener(OnDialogActionListener l){ | |
this.mDialogListener = l; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View v = inflater.inflate(R.layout.dialog_firstload, container, false); | |
btnOK = (Button) v.findViewById(R.id.btn_ok); | |
btnCancel = (Button) v.findViewById(R.id.btn_cancel); | |
btnOther = (Button) v.findViewById(R.id.btn_other); | |
tvTitle = (TextView) v.findViewById(R.id.tv_title); | |
tvInfo =(TextView) v.findViewById(R.id.tv_info); | |
Bundle args = getArguments(); | |
if(args != null){ | |
String title = args.getString(TITLE); | |
String message = args.getString(MESSAGE); | |
String yesBtnText = args.getString(YES_BTN_TEXT); | |
String cancelBtnText = args.getString(CANCEL_BTN_TEXT); | |
tvTitle.setText(title); | |
tvInfo.setText(message); | |
btnOK.setText(yesBtnText); | |
btnCancel.setText(cancelBtnText); | |
if(args.containsKey(EXIT_BTN_TEXT) && !TextUtils.isEmpty(args.getString(EXIT_BTN_TEXT))){ | |
btnOther.setText(args.getString(EXIT_BTN_TEXT)); | |
btnOther.setVisibility(View.VISIBLE); | |
} | |
} | |
btnOK.setOnClickListener(this); | |
btnCancel.setOnClickListener(this); | |
btnOther.setOnClickListener(this); | |
return v; | |
} | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
Dialog d = super.onCreateDialog(savedInstanceState); | |
d.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
d.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); | |
return d; | |
} | |
@Override | |
public void onClick(View v) { | |
switch (v.getId()) { | |
case R.id.btn_ok: | |
if(mDialogListener != null){ | |
mDialogListener.onOKClick(); | |
} | |
this.dismiss(); | |
break; | |
case R.id.btn_cancel: | |
if(mDialogListener != null){ | |
mDialogListener.onCancel(); | |
} | |
this.dismiss(); | |
break; | |
case R.id.btn_other: | |
if(mDialogListener != null){ | |
mDialogListener.onOther(); | |
} | |
this.dismiss(); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment