アクション バーのメニュー項目から呼び出したい 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.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 クラスは、
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?
}
}
種のポップアップウィンドウのスクリーンショット:
現在の問題は、SQL およびその他のメソッドの種のポップアップウィンドウの実装に関連しています... MainActivity の onOptionsItemSelected の case-switch ステートメントからこれらを呼び出す方法は?
前もって感謝します。