我已經寫了一些行來彈出一個窗體,按Button
。現在我試圖停用Button
,如果它按下,所以它不會再次打開。禁用一個按鈕,如果它已被執行
這裏是塔的主要活動文件:
package com.javacodegeeks.android.fragmentstest;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;
import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.DialogInterface;
@SuppressLint("InflateParams")
public class MainActivity extends Activity implements OnClickListener {
ImageView mButton1;
Context contex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton1 = (ImageView) findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@SuppressWarnings("null")
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupform, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnbutton1 = (Button)popupView.findViewById(R.id.login);
btnbutton1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnbutton1, 50, 250);
}
});
}
我們做出說明在這裏,這是代碼的一部分,因此有在這之後更多。但我卡在這一部分!
如果我想關閉該彈出窗口後啓用它呢? – 2014-10-31 20:31:29
這就是爲什麼我添加了關於重寫onDismiss()的一點。這將被稱爲當你關閉彈出 – codeMagic 2014-10-31 20:39:41
年,只是顯示這一點。那麼這應該在哪裏? – 2014-10-31 21:16:04