alertDialogBuilder.setPositiveButton("Visit MOMA", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Uri web_page = Uri.parse(URL);
Intent baseIntent = new Intent(Intent.ACTION_VIEW, web_page);
Intent chooserIntent = Intent.createChooser(baseIntent,"Open "+URL+" with:");
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
if(baseIntent.resolveActivity(getPackageManager())!=null){
Log.i(TAG,"Chooser Intent Action22:" + chooserIntent.getAction());
startActivity(chooserIntent);
}
}
});
答案 0 :(得分:0)
//你可以使用这个
//打开对话框的示例代码如下
public class DandGDialogActivity extends DialogFragment{
private View mViewHolder;
private EditText etHeight,etWeight,etHC;
private TextView tvDate;
//private SystemAppPreferences mSysAppPrefs;
public static DandGDialogActivity getInstance() {
DandGDialogActivity fragment = new DandGDialogActivity ();
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// mSysAppPrefs = SystemAppPreferences.getInstance(getActivity());
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
AlertDialog.THEME_HOLO_LIGHT);
builder.setCancelable(false);
LayoutInflater inflater = getActivity().getLayoutInflater();
mViewHolder = inflater.inflate(R.layout.vitals, null);
etHeight=(EditText) mViewHolder.findViewById(R.id.editTextheight);
etWeight=(EditText) mViewHolder.findViewById(R.id.editTextweight);
etHC=(EditText) mViewHolder.findViewById(R.id.editTexthc);
tvDate=(TextView) mViewHolder.findViewById(R.id.textViewdate);
tvDate.setText(new SimpleDateFormat("dd-MM-yyyy").format(new Date()));
tvDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar mdate=Calendar.getInstance();
int year=mdate.get(Calendar.YEAR);
int monthOfYear=mdate.get(Calendar.MONTH);
int dayOfMonth=mdate.get(Calendar.DATE);
DatePickerDialog dpd = new DatePickerDialog(getActivity(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
// Display Selected date in textbox
tvDate.setText(dayOfMonth + "-"
+ (monthOfYear + 1) + "-" + year);
}
}, year, monthOfYear,dayOfMonth);
dpd.show();
dpd.setCanceledOnTouchOutside(false);
}
});
//builder.setTitle("Admin Login");
mViewHolder.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
builder.setView(mViewHolder)
.setPositiveButton("Save",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (etHeight.length() == 0||etWeight.length()==0||etHC.length()==0) {
Toast.makeText(getActivity(),
" Please enter all field Properly ", Toast.LENGTH_SHORT)
.show();
return;
}
else {
Toast.makeText(getActivity(),
" All feilds are ok ", Toast.LENGTH_SHORT)
.show();
dismiss();
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dismiss();
}
});
return builder.create();
}
}
//要调用对话框,您必须使用以下代码
alertdialog.show(getFragmentManager(), null);