문제

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