AlertDialog的问题检索组件-android
|
我正在尝试使用视图构建一个Alertdialog,并访问TextView来设置其文本值。这是代码:
private void ShowLogDialog() {
AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setIcon(R.drawable.icon);
ad.setTitle(\"Ultimate Logs\");
ad.setView(LayoutInflater.from(this).inflate(R.layout.log_layout, null));
TextView text = (TextView)ad.findViewById(R.id.logTextView_log); // RETURNS NULL
//Log.i(TAG, \"Into ShowLogDialog : GoT TextView = \" + text);
//String logsText = \"\";
//text.setText(logsText);
ad.setButton(\"Ok\", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
}
log_layout.xml
<LinearLayout android:id=\"@+id/linearLayout1\" android:layout_width=\"match_parent\" android:layout_height=\"match_parent\"
android:orientation=\"vertical\" android:scrollbars=\"vertical\" android:scrollbarAlwaysDrawVerticalTrack=\"true\" xmlns:android=\"http://schemas.android.com/apk/res/android\">
<TextView android:layout_height=\"wrap_content\" android:text=\"TextView\" android:id=\"@+id/**logTextView_log**\" android:layout_width=\"wrap_content\"></TextView>
</LinearLayout>
为什么我无法访问TextView?它返回null并引发NullPointerException。我无法直接使用findBiewById进行访问,因此使用的是ad.findViewById,但我只收到它为null。谁能帮我知道我要去哪里错了!
谢谢
没有找到相关结果
已邀请:
3 个回复
土投
逆捐凶撤小
**是..?
桑娠贯涤
返回到
变量? (以下代码未经测试)