0

I have a PopupWindow that I'd like to call from a menu item in the action bar. PopupWindow class is,

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.
}

MainActivity class is,

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?
}
}

Screenshot of speciesPopupWindow:

enter image description here

The current problem is related to implementing the SQL and other methods in speciesPopupWindow...how to call these from the case-switch statement in onOptionsItemSelected in MainActivity?

Thanks in advance.

portsample
  • 1,986
  • 4
  • 19
  • 35

1 Answers1

0

Changing editSpeciesTable in MainActivity to...

public void editSpeciesTable(){
    new speciesPopupWindow(MainActivity.this).init();
}

results in speciesPopupWindow.class working properly. Thanks.

portsample
  • 1,986
  • 4
  • 19
  • 35