gpt4 book ai didi

java - 我正在尝试在 Android 上实现此代码,我对此很菜鸟

转载 作者:行者123 更新时间:2023-12-02 05:03:43 24 4
gpt4 key购买 nike

我正在尝试制作一个学校应用程序,我想在每次按下按钮时制作一个弹出框。

但随后我收到错误:

expected class or package

从这行代码:

showPopUp.OnClickListener

第 25 行

public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button showPopUp = (Button) findViewById(R.id.button);
showPopUp.OnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
showSimplePopUp();
}
});
}

private void showSimplePopUp() {

AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("Opening Line");
helpBuilder.setMessage("You popped my jingles up");
helpBuilder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
}
});

// Remember, create doesn't show the dialog
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
}




@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);
}
}

最佳答案

看起来像是一个错字,但应该是:

Button showPopUp = (Button) findViewById(R.id.button);
showPopUp.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
showSimplePopUp();
}
});

关于java - 我正在尝试在 Android 上实现此代码,我对此很菜鸟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28001399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com