I have a AlertDialog.Builder in my Fragment Page and it shows three EditText (in a xml file). Now I'd like to add a button at the top of the AlertDialog and on its click change the text of two of them.

It is like:

Button : Get coordinates

1st EdiText : latitude

2st EdiText : longitude

有帮助吗?

解决方案

If you want a button added in xml file to be displayed in AlertDialog, just inflate the layout

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(false);
builder.setView(layout);

where "layout" is inflated view

LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.activity_filename,null); // specify your xml layout here

then use "layout" to get id of the button

Button btn=(Button)layout.findViewById(R.id.getCoordBtn);

add click listener to it and perform whatever you want

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top