I have a button on my second activity (pre-messages)
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/Button40"
android:src="@drawable/back"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:focusable="true"
android:onClick=""
android:clickable="true" />
That I must close my activity to return to the primary activity, I am dealing with the code:
Button cerrar= (Button) findViewById(R.id.Button40);
cerrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
At the moment of inserting it into the java file of my second activity just below:
package com.globalstar.st300r;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
public class MensajesPredet extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mensajes_predet);
}
Button cerrar = (Button) findViewById(R.id.Button40);
cerrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
finish();
}
@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_mensajes_predet, 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);
}
}
And this is the java of my first activity:
package com.globalstar.st300r;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Send button */
public void predefinido(View view) {
Intent intent = new Intent(this, MensajesPredet.class);
startActivity(intent);
}
@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);
}
}
but it marks me 4 errors:
1) when I put it on, it detects me the @override as a comment and it marks the legend "Annotations are not allowed here"
2) in the code close. SetOnClickListener check (Can not resolve symbol) and SetOnclickListener in red
3) (View v) mark error
4) Onclick is never used
I would appreciate your support !!