Я хочу создать кнопку, которая закрывает текущую активность. Как кнопка «возврат». Вот фрагменты кода я попытался:Кнопка возврата - недоступна
Вот полный .java:
public class OtherApps extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other_apps);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.otherappsmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.previous:
finish();
break;
case R.id.home:
Context context = getApplicationContext();
CharSequence text = "Activitys are not closed!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
Intent intent = new Intent(this, MainActivity.class);
this.startActivity(intent);
break;
case R.id.exit:
finish();
System.exit(0);
case R.id.help:
String url = "http://www.google.de/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
return true;
final Button OtherApps = (Button)findViewById(R.id.previousbutton);
OtherApps.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
return true;
}
}
Но Eclipse, говорит, что «первая линия недостижим». Кто-нибудь знает, в чем ошибка?
Спасибо за помощь!
«первой линии» - какая линия точно? – Simon
* Который * код недостижим? –
Первая строка каждого кода. «Кнопка Button = (кнопка) findViewById (R.id.previousbutton);" и "final Button OtherApps = (кнопка) findViewById (R.id.previousbutton);" – YouDeveloper