I am trying to use a button made in XML in a alert dialog but the app crashes when the activity tries to load.
package dtt.bob.rsrpechhulp;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
public class CallWindow extends DialogFragment implements View.OnClickListener{
LayoutInflater inflater;
View v;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
Button annuleren = (Button) v.findViewById(R.id.annuleren); //here is the problem I assume
annuleren.setOnClickListener(this);
inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.call, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(v);
return builder.create();
}
public void onClick(View v) {
switch(v.getId()){
case R.id.annuleren:
annulerenClick();
break;
}
}
//annuleren
private void annulerenClick(){
dismiss();
}
Any ideas on how to fix this? I have used the onClickListeners in other activities but they were in onCreate methods instead of onCreateDialog methods.