我打算构建一个alertdialog视图并访问TextView来设置其文本值。下面的代码:AlertDialog的组件检索问题 - android
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。任何人都可以帮助我知道我哪里错了!
谢谢
有什么办法可以设置AlertDialog的文字字体大小。我的意思是,我可以更改添加到SetMessage()的文本大小。如果这可以实现,那么我的工作也可以完成。 – Tvd 2011-04-22 10:38:46