我正在尝试显示dialog
框。现在程序没有崩溃,所以没有LogCat可以显示。单击按钮时,没有任何可见的事情发生。我缺少哪一行代码阻止dialog
框显示?
Java代码:
public class Results extends Activity {
Button detailsBtn;
final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultsmain);
detailsBtn = (Button)findViewById(R.id.detailsBtn);
detailsBtn.setText("Details");
detailsBtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.resultsdetailsdisplay);
dialog.setTitle("Detailssss - TESTING");
TextView title = (TextView)dialog.findViewById(R.id.title);
title.setText("TITLE - TESTING");
Button close = (Button)dialog.findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
dialog.dismiss();
}
});
}
});
}
}
resultsdetailsdisplay.xml:
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/scroll" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_centerHorizontal="true"
android:gravity="center" />
</RelativeLayout>
答案 0 :(得分:3)
可能是因为您没有为show()
调用dialog
方法。
添加
dialog.show();