Android 从Actionbar菜单项调用modifiedPopupWindow类:这可能吗?

Android 从Actionbar菜单项调用modifiedPopupWindow类:这可能吗?,android,android-activity,android-actionbar,menuitem,android-popupwindow,Android,Android Activity,Android Actionbar,Menuitem,Android Popupwindow,我有一个弹出窗口,我想从操作栏中的菜单项调用它。PopupWindow类是 public class speciesPopupWindow { Context ctx; Button btnDismiss, ...; public speciesPopupWindow(Context ctx){ this.ctx = ctx; } public void init(View v){ LayoutInflater inflater = (LayoutInflater) ctx.getS

我有一个弹出窗口,我想从操作栏中的菜单项调用它。PopupWindow类是

public class speciesPopupWindow {
Context ctx;
Button btnDismiss, ...;

public speciesPopupWindow(Context ctx){
    this.ctx = ctx;
}
public void init(View v){ 
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService...
View popUpView = inflater.inflate(R.layout.popup_layout,...
final PopupWindow popup = new PopupWindow(popUpView,...
popup.setContentView(popUpView);
popup.showAtLocation(v, Gravity.CENTER_HORIZONTAL, -10, 100);
...
btnSaveRecord = (Button) popUpView.findViewById(R.id.btnSaveRecordxml);
btnSaveRecord.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){saveRecord(v);
        }});
...
    }
public void saveRecord(View v){
    String szSpecies = edSpeciesLookup.getText().toString();            
    if(szSpecies.matches("")){          
    }else{
        db.execSQL("INSERT INTO speciesLookupDb (species) VALUES ('"+szSpecies+"')");
        clearForm(v);
    }
  }
//...more delete, update, first, previous, next, and last sql calls.
}
public class MainActivity extends Activity{
    public static Context appContext;
...
public speciesPopupWindow speciesPopupWindow;
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.corax, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.menuitem_editSpeciesTable:
            editSpeciesTable(null);
            return true;
    }
    return false;
}
//2/13- Adjusted editSpeciesTable below per suggested answer.
public void editSpeciesTable(View v){
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    PopupWindow speciesPopupWindow = new PopupWindow(inflater.inflate(R.layout.popup_layout, null, false),500,500,true);
    speciesPopupWindow.showAtLocation(this.findViewById(R.id.fragment_placeholder), Gravity.CENTER, 0, 0);
//shows popup_layout.xml layout fine...but how to call speciesPopupWindow.init() for sql logic?
}
}
主要活动类是

public class speciesPopupWindow {
Context ctx;
Button btnDismiss, ...;

public speciesPopupWindow(Context ctx){
    this.ctx = ctx;
}
public void init(View v){ 
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService...
View popUpView = inflater.inflate(R.layout.popup_layout,...
final PopupWindow popup = new PopupWindow(popUpView,...
popup.setContentView(popUpView);
popup.showAtLocation(v, Gravity.CENTER_HORIZONTAL, -10, 100);
...
btnSaveRecord = (Button) popUpView.findViewById(R.id.btnSaveRecordxml);
btnSaveRecord.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){saveRecord(v);
        }});
...
    }
public void saveRecord(View v){
    String szSpecies = edSpeciesLookup.getText().toString();            
    if(szSpecies.matches("")){          
    }else{
        db.execSQL("INSERT INTO speciesLookupDb (species) VALUES ('"+szSpecies+"')");
        clearForm(v);
    }
  }
//...more delete, update, first, previous, next, and last sql calls.
}
public class MainActivity extends Activity{
    public static Context appContext;
...
public speciesPopupWindow speciesPopupWindow;
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.corax, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.menuitem_editSpeciesTable:
            editSpeciesTable(null);
            return true;
    }
    return false;
}
//2/13- Adjusted editSpeciesTable below per suggested answer.
public void editSpeciesTable(View v){
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    PopupWindow speciesPopupWindow = new PopupWindow(inflater.inflate(R.layout.popup_layout, null, false),500,500,true);
    speciesPopupWindow.showAtLocation(this.findViewById(R.id.fragment_placeholder), Gravity.CENTER, 0, 0);
//shows popup_layout.xml layout fine...but how to call speciesPopupWindow.init() for sql logic?
}
}
speciesPopupWindow的屏幕截图:

当前的问题与在speciesPopupWindow中实现SQL和其他方法有关…如何从MainActivity中OnOptions ItemSelected中的case switch语句调用这些方法


提前感谢。

将Main活动中的editSpeciesTable更改为

public void editSpeciesTable(){
    new speciesPopupWindow(MainActivity.this).init();
}
导致speciesPopupWindow.class正常工作。谢谢