我需要帮助将数据从父活动传递到对话框。我想在longclick上设置文本。
public boolean onLongClick(View v) {
RememberLongPressedButton(v);
String buttonText = GetButtonText(v);
DialogFragment newFragment = new SomeDialogFragment();
newFragment.show(getFragmentManager(), _APPNAME);
if(!(buttonText.equals(" ") || buttonText.isEmpty()))
DataToEditText(newFragment,buttonText);
return true;
}
Dialog片段类的代码
public class SomeDialogFragment extends DialogFragment {
public interface SomeDialogFragment {
void onDialogPositiveClick(DialogFragment dialog);
void onDialogNegativeClick(DialogFragment dialog);
}
private SomeDialogFragmentListener _listener;
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
if(context instanceof SomeDialogFragmentListener)
_listener = (SomeDialogFragmentListener) context;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(context.toString()
+ " must implement SomeDialogFragmentListener");
}
}
当我拨打此线路时,我的应用程序崩溃了
Dialog dialog = dialogFragment.getDialog();
EditText editText = (EditText) dialog.findViewById(R.id.dialog_text);
答案 0 :(得分:0)
我解决了问题,感谢我们向我发送正确的方向
../angular-dashboard/
├── LICENSE
├── README.md
├── dist
├── package.json
├── src
│ ├── app
│ │ ├── app.js
│ │ ├── controllers
│ │ │ └── dashboardController.js
│ │ ├── dashboards
│ │ │ ├── home
│ │ │ │ ├── homeDashboard.component.js
│ │ │ │ ├── homeDashboard.controller.js
│ │ │ │ └── templates
│ │ │ │ └── homeDashboard.template.html
│ │ │ └── other
│ │ │ ├── otherDashboard.component.js
│ │ │ ├── otherDashboard.controller.js
│ │ │ └── templates
│ │ │ └── otherDashboard.template.html
│ │ ├── filters
│ │ │ └── object2Array.js
│ │ ├── services
│ │ │ └── storage.service.js
│ │ └── widgets
│ │ └── a_widget
│ │ ├── aWidget.component.js
│ │ ├── aWidget.controller.js
│ │ ├── aWidget.settings.controller.js
│ │ └── templates
│ │ ├── aWidget.settings.template.html
│ │ └── aWidget.template.html
│ ├── index.html
│ └── style
│ ├── style-common.css
│ └── style.css
└── webpack.config.js
15 directories, 22 files