Почему я не могу создать всплывающее диалоговое окно внутри моего fab.setOnClickListener(View
в методе onCreate
?
Это из-за синтаксиса?Я пропускаю выражения?Мой код устарел, так как мой инструктор - старый курс удеми?
public class MainActivity extends AppCompatActivity {
private AlertDialog.Builder dialogBuilder;
private AlertDialog dialog;
private EditText groceryItem;
private EditText getGroceryItem;
private EditText quantity;
private Button saveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
// === error appears on the next line ===
fab.setOnClickListener(View,
createPopupDialog());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void createPopupDialog() {
dialogBuilder = new AlertDialog.Builder(this);
View view = getLayoutInflater().inflate(R.layout.popup, null);
groceryItem = view.findViewById(R.id.groceryItem);
quantity = view.findViewById(groceryQty);
saveButton = view.findViewById(R.id.saveButton);
dialogBuilder.setView(view);
dialog = dialogBuilder.create();
dialog.show();
}
}