Android Alert Dialog unable to find view

前端 未结 4 1633
花落未央
花落未央 2020-12-07 01:55

I\'m having trouble getting an AlertDialog to pass text back to the activity that calls it. It seems the issue is that it fails to find the proper EditText when calling fin

4条回答
  •  醉酒成梦
    2020-12-07 02:02

    Your inflating a layout and you have this builder.setView(modifyView);

    So to initialize edittext replace

     final EditText editText = (EditText)getActivity().findViewById(R.id.modificationText);
    

    by

     final EditText editText = (EditText) modifyViewfindViewById(R.id.modificationText);
    

    findViewById looks for a view with id provided in the current inflated layout. You don't need getActivity instead use theinflated view object to initialize your EditText.

    public final Activity getActivity ()
    
    Added in API level 11
    Return the Activity this fragment is currently associated with.
    

提交回复
热议问题