我的班级Android
extends Dialog
public class DialogSearch extends Dialog{
public ImageButton imageButtonCancel ;
public DialogSearch(Context context, int theme) {
super(context, theme);
setContentView(R.layout.finddialog);
imageButtonCancel = (ImageButton) findViewById(R.id.imageButtonFindCancel);
imageButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//hide();
dismiss();
}
});
this.show();
}
}
这不是我的ActivityClass
,我可以从ActivityClass
进行实例化,但是当我点击imageButtonCancel
关闭时,我无效。我尝试了hide()
和close()
两种方法。
更新日期
这是我的R.Layout.finddialog
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="@+id/editTextFind"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="write here"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<ImageButton
android:id="@+id/imageButtonFindSearch"
android:layout_toRightOf="@+id/editTextFind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/find_icone"
android:layout_marginRight="10px"
/>
<ImageButton
android:id="@+id/imageButtonFindCancel"
android:layout_below="@+id/radioGroupeFind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/cancel_icone"
android:layout_alignRight="@+id/imageButtonFindSearch"
/>
</RelativeLayout>
更新日期
我是从ActivityClass
public class mapActivity extends Activity {
private ImageButton buttonSearch ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
buttonSearch = (ImageButton) findViewById(R.id.buttonSearchMain) ;
buttonSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialogSearch = new DialogSearch(mapActivity.this,R.style.FullHeightDialog); // this for not display dialog title part
}
});
}
}
感谢。
答案 0 :(得分:1)
尝试DialogSearch.this.dismiss();
答案 1 :(得分:1)
试试这个...使用onCreate()方法......
public class DialogSearch extends Dialog {
public DialogSearch(Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// hides title bar...
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.finddialog);
ImageButton imageButtonCancel = (ImageButton) findViewById(R.id.imageButtonFindCancel);
imageButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// hide();
dismiss();
}
});
}
}