當我將鼠標懸停在「setOnClickListener」下方的紅色曲線上時,彈出消息顯示「無法解析符號setOnClickListener」,「@Override」顯示「此處不允許註釋」。而「View v」中的v也給我一個錯誤。我在哪裏搞砸了?我的是我的setOnClickListener給我一個錯誤?
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));
}
}
}
這解決了它。非常感謝! – agentmg123