单击列表项时出现应用程序错误
当我单击列表项时,我收到错误并关闭应用程序。如何修复它?我哪里错了。 我需要在自定义对话框窗口
customdialoglayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:background="@drawable/kmp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/dialog_title"
android:textColor="#FFF"
android:textSize="16sp"
android:layout_width="fill_parent" android:gravity="center" android:layout_height="30dp" android:layout_marginTop="5dp"/>
<TextView android:id="@+id/dialog_text"
android:textColor="#FFF"
android:layout_height="35dp" android:layout_width="fill_parent" android:gravity="center"/>
中显示文本 WTF
在 mainActivity 中
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String toastMessage = messages.get(position).toString();
Builder customdialoglayout = new AlertDialog.Builder(this)
.setCancelable(true)
.setIcon(R.drawable.icon);
TextView text = (TextView) findViewById(R.id.dialog_text);
text.setText("WTF");
setContentView(R.layout.customdialoglayout);
}
已解决问题:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.customdialoglayout);
dialog.setTitle(rssTitle);
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.dialog_text);
text.setText("WTF");
dialog.show();
When i click on list item im get error and closing app. how to fix it? where im wrong.
im need to show text WTF in custom dialog window
customdialoglayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:background="@drawable/kmp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/dialog_title"
android:textColor="#FFF"
android:textSize="16sp"
android:layout_width="fill_parent" android:gravity="center" android:layout_height="30dp" android:layout_marginTop="5dp"/>
<TextView android:id="@+id/dialog_text"
android:textColor="#FFF"
android:layout_height="35dp" android:layout_width="fill_parent" android:gravity="center"/>
in mainActivity
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String toastMessage = messages.get(position).toString();
Builder customdialoglayout = new AlertDialog.Builder(this)
.setCancelable(true)
.setIcon(R.drawable.icon);
TextView text = (TextView) findViewById(R.id.dialog_text);
text.setText("WTF");
setContentView(R.layout.customdialoglayout);
}
fixed problem already by:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.customdialoglayout);
dialog.setTitle(rssTitle);
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.dialog_text);
text.setText("WTF");
dialog.show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用
.Builder
此处 Android 开发指南参考!
<代码>
<代码>
You have to use the
.Builder
here a reference to Android dev Guide!