0

So I built a back button and I added some simple generic java code to it with hopes that it would work. Well I was wrong because every time I click on the back button the app crashes, and then I end up at the home menu. The file that I want to bring up when clicking on the back button is intertwined with many other files. By intertwined I mean that there are about three other buttons that lead to that same java file. I'm thinking that my code must be too basic, however I might be wrong.

java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;




 public abstract class ViewVideos extends Activity implements OnClickListener {


private Button bback;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.viewvideo);
    bback = (Button) findViewById(R.id.bback);
    bback.setOnClickListener(this);

}


public void onClick(View view) {
    Intent intent = new Intent(this, PickAnmActivity.class);
    startActivity(intent);
}
}

xml

 <?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tn_anm_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PickAnmActivity"
>



<VideoView
  android:id="@+id/vviidd"
    android:layout_height="0dp"
    android:layout_width="wrap_content"
    android:layout_weight="10"
/>


<Button
    android:id="@+id/bback"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="15dp"
    android:layout_weight="1"
    android:text="@string/b_back"
    android:onClick="bbaacckk"
/>


</LinearLayout>
worker
  • 33
  • 3
  • 13

2 Answers2

1

You need to add code inside the function setOnClickListener.

Follow this example Trigger back-button functionality on button click in Android

Community
  • 1
  • 1
amaiaeskisabel
  • 334
  • 1
  • 5
0
bback = (Button) findViewById(R.id.bback);
bback.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
         // put what happens when you click it here...
     }
});
derfect
  • 622
  • 2
  • 6
  • 14