无法操纵TextView以进行自定义对话框

时间:2013-06-04 21:16:11

标签: android textview

这将抛出空指针异常并使应用程序崩溃。无法弄清楚为什么。这可能是因为一些时髦的线程业务。我想也许处理程序可能会修复它。如果有人有任何想法我会全力以赴,我会在此期间尝试一下。感谢

以下是我遇到的错误:

06-04 15:42:34.644: W/dalvikvm(6535): threadid=1: thread exiting with uncaught exception (group=0x40dca438)

传播错误的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

builder.setView(inflater.inflate(R.layout.my_layout, null));

Log.i(TAG, "Getting TextView and appending");

((TextView) findViewById(R.id.tvName)).append("appended string");

builder.create().show();

1 个答案:

答案 0 :(得分:0)

LayoutInflater inflater = getActivity().getLayoutInflater();

View view = inflater.inflate(R.layout.my_layout, null);

builder.setView(view);

Log.i(TAG, "Getting TextView and appending");

((TextView) view.findViewById(R.id.tvName)).append("appended string");

builder.create().show();

如果R.id.tvName属于R.layout.my_layout,您必须使用膨胀的视图来检索它