这是我的MainActivity类别中创建一个AlertDialog我的静态内部类:可点击超链接在DialogFragment
public static class AboutDialogFragment extends DialogFragment {
public static AboutDialogFragment newInstance() {
AboutDialogFragment frag = new AboutDialogFragment();
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_dialog_about)
.setTitle(R.string.about)
.setMessage(R.string.about_message)
..........
.create();
}
}
而且我展示它,当你按下它里面MainActivity菜单项:
case R.id.about:
DialogFragment aboutFragment = AboutDialogFragment.newInstance();
aboutFragment.show(getSupportFragmentManager(), "about_dialog");
// Make links clickable
((TextView) aboutFragment.getDialog().findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
return true;
我正在尝试使用注释行使消息文本中的链接可点击。
我发现这种方法here它使用普通的对话框(没有片段)时工作。
但是,这是我第一次尝试在DialogFragment上使用它,并且在尝试查找视图时总是遇到NullPointerException。
我也试过aboutFragment.getView().findViewById(android.R.id.message)
但是也返回null。
也许我太早/在错误的地方调用代码?
任何想法都会很棒!
编辑:只是尝试((TextView) v.getRootView().findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
和 ((TextView) v.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
在onCreateView(),并没有成功也试过在onCreateDialog()。
仍然得到空指针异常......
请参阅我的编辑。在调用View v = super.onCreateView(...)之后,我在onCreateDialog()和onCreateView()方法中都尝试过了,但它不起作用! – Kavi 2012-02-04 19:32:18