【发布时间】:2017-01-18 15:57:47
【问题描述】:
当我将鼠标悬停在“setOnClickListener”下的波浪形红线上时,弹出消息“无法解析符号 setOnClickListener”,“@Override”显示“此处不允许注释”。而“View v”中的 v 也给了我一个错误。我哪里搞砸了?
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class EmailReceiptActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_receipt);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_options_menu, menu);
menu.findItem(R.menu.main_options_menu).setIntent(
new Intent(EmailReceiptActivity.this, LaunchActivity.class));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//use the id of the item from main_options_menu
if (id == R.id.logoff_menu_item) {
super.onOptionsItemSelected(item);
startActivity(item.getIntent());
}
return true;
}
Button btn_send = (Button)findViewById(R.id.send_receipt_button);
btn_send.setOnClickListener(new View.OnClickListener(){
@Override
//Use the name of the function you assigned to the xml design of the button
public void onClick(View v){
//Use the name of this class, and the name class where you want to be taken when the button is clicked.
startActivity (new Intent(EmailReceiptActivity.this, SuccessActivity.class));
}
}
}
【问题讨论】:
标签: java android android-studio button