为什么我不能在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();
}
}
答案 0 :(得分:1)
您没有在$fso = New-Object -com "Scripting.FileSystemObject"
$Versionarray = (13..20)
$folder =
$fso.GetFolder("$env:USERPROFILE\appdata\local\Microsoft\OneDrive")
foreach ($subfolder in $folder.SubFolders)
{
If ($subfolder.Name -match "$Versionarray")
{
remove-item $subfolder.Path -Verbose
}
}
中传递正确的参数。
像这样创建侦听器:
setOnClickListener()
答案 1 :(得分:0)
我认为您想使用lambda表达式。如果是这样,这是正确的语法:
fab.setOnClickListener((View v) -> {
createPopupDialog();
});