Button not responding to onClick method









up vote
-2
down vote

favorite












I am developing an Android app and I want to inflate a dialog with the press of a button (I've already done that), but one specific button does not work, and I don't really know why.



My code:



public class SearchUser extends AppCompatActivity

private static final String TAG = "SearchUser";

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b = (Button) findViewById(R.id.btnSearchUser);
b.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
AlertDialog.Builder mBuilder = new AlertDialog.Builder(SearchUser.this);
View mView = getLayoutInflater().inflate(R.layout.searchpopup, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
btnSearch.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);

);
dialog.show();

);



LAYOUT XML FILE:



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

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/btnSearchUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/search_user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.129" />

<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/log_out"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="1.0"
mapbox:layout_constraintStart_toStartOf="@+id/mapView"
mapbox:layout_constraintTop_toTopOf="parent"
mapbox:layout_constraintVertical_bias="0.0" />

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="parent"

mapbox:mapbox_cameraTargetLat="-34.6131500"
mapbox:mapbox_cameraTargetLng="-58.3772300"
mapbox:mapbox_cameraZoom="12"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10">

</com.mapbox.mapboxsdk.maps.MapView>

<Button
android:id="@+id/startButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:enabled="true"
android:text="@string/crear_fiesta"
android:textColor="@color/mapboxGrayLight"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent" />




I have tried putting a toast message inside the onClick method but nothing happens, so I guess it just does not enter there.



Anyone know why? Thanks for any answer :D










share|improve this question























  • your layout xml file?
    – Ramees Thattarath
    Nov 10 at 19:28










  • That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
    – Mike M.
    Nov 10 at 19:30






  • 1




    you have used btnSearch but not initialized it anywhere before using it.
    – Rahul Kumar
    Nov 10 at 19:54














up vote
-2
down vote

favorite












I am developing an Android app and I want to inflate a dialog with the press of a button (I've already done that), but one specific button does not work, and I don't really know why.



My code:



public class SearchUser extends AppCompatActivity

private static final String TAG = "SearchUser";

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b = (Button) findViewById(R.id.btnSearchUser);
b.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
AlertDialog.Builder mBuilder = new AlertDialog.Builder(SearchUser.this);
View mView = getLayoutInflater().inflate(R.layout.searchpopup, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
btnSearch.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);

);
dialog.show();

);



LAYOUT XML FILE:



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

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/btnSearchUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/search_user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.129" />

<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/log_out"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="1.0"
mapbox:layout_constraintStart_toStartOf="@+id/mapView"
mapbox:layout_constraintTop_toTopOf="parent"
mapbox:layout_constraintVertical_bias="0.0" />

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="parent"

mapbox:mapbox_cameraTargetLat="-34.6131500"
mapbox:mapbox_cameraTargetLng="-58.3772300"
mapbox:mapbox_cameraZoom="12"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10">

</com.mapbox.mapboxsdk.maps.MapView>

<Button
android:id="@+id/startButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:enabled="true"
android:text="@string/crear_fiesta"
android:textColor="@color/mapboxGrayLight"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent" />




I have tried putting a toast message inside the onClick method but nothing happens, so I guess it just does not enter there.



Anyone know why? Thanks for any answer :D










share|improve this question























  • your layout xml file?
    – Ramees Thattarath
    Nov 10 at 19:28










  • That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
    – Mike M.
    Nov 10 at 19:30






  • 1




    you have used btnSearch but not initialized it anywhere before using it.
    – Rahul Kumar
    Nov 10 at 19:54












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I am developing an Android app and I want to inflate a dialog with the press of a button (I've already done that), but one specific button does not work, and I don't really know why.



My code:



public class SearchUser extends AppCompatActivity

private static final String TAG = "SearchUser";

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b = (Button) findViewById(R.id.btnSearchUser);
b.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
AlertDialog.Builder mBuilder = new AlertDialog.Builder(SearchUser.this);
View mView = getLayoutInflater().inflate(R.layout.searchpopup, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
btnSearch.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);

);
dialog.show();

);



LAYOUT XML FILE:



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

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/btnSearchUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/search_user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.129" />

<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/log_out"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="1.0"
mapbox:layout_constraintStart_toStartOf="@+id/mapView"
mapbox:layout_constraintTop_toTopOf="parent"
mapbox:layout_constraintVertical_bias="0.0" />

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="parent"

mapbox:mapbox_cameraTargetLat="-34.6131500"
mapbox:mapbox_cameraTargetLng="-58.3772300"
mapbox:mapbox_cameraZoom="12"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10">

</com.mapbox.mapboxsdk.maps.MapView>

<Button
android:id="@+id/startButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:enabled="true"
android:text="@string/crear_fiesta"
android:textColor="@color/mapboxGrayLight"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent" />




I have tried putting a toast message inside the onClick method but nothing happens, so I guess it just does not enter there.



Anyone know why? Thanks for any answer :D










share|improve this question















I am developing an Android app and I want to inflate a dialog with the press of a button (I've already done that), but one specific button does not work, and I don't really know why.



My code:



public class SearchUser extends AppCompatActivity

private static final String TAG = "SearchUser";

@Override
public void onCreate(@Nullable Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b = (Button) findViewById(R.id.btnSearchUser);
b.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
AlertDialog.Builder mBuilder = new AlertDialog.Builder(SearchUser.this);
View mView = getLayoutInflater().inflate(R.layout.searchpopup, null);
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
btnSearch.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);

);
dialog.show();

);



LAYOUT XML FILE:



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

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/btnSearchUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/search_user"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="0.0"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="@+id/mapView"
mapbox:layout_constraintVertical_bias="0.129" />

<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/log_out"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="@+id/mapView"
mapbox:layout_constraintHorizontal_bias="1.0"
mapbox:layout_constraintStart_toStartOf="@+id/mapView"
mapbox:layout_constraintTop_toTopOf="parent"
mapbox:layout_constraintVertical_bias="0.0" />

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent"
mapbox:layout_constraintTop_toTopOf="parent"

mapbox:mapbox_cameraTargetLat="-34.6131500"
mapbox:mapbox_cameraTargetLng="-58.3772300"
mapbox:mapbox_cameraZoom="12"
mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10">

</com.mapbox.mapboxsdk.maps.MapView>

<Button
android:id="@+id/startButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:enabled="true"
android:text="@string/crear_fiesta"
android:textColor="@color/mapboxGrayLight"
mapbox:layout_constraintBottom_toBottomOf="parent"
mapbox:layout_constraintEnd_toEndOf="parent"
mapbox:layout_constraintStart_toStartOf="parent" />




I have tried putting a toast message inside the onClick method but nothing happens, so I guess it just does not enter there.



Anyone know why? Thanks for any answer :D







java android button






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 22:36









shashank chandak

160111




160111










asked Nov 10 at 19:27









Franco Estevez

85




85











  • your layout xml file?
    – Ramees Thattarath
    Nov 10 at 19:28










  • That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
    – Mike M.
    Nov 10 at 19:30






  • 1




    you have used btnSearch but not initialized it anywhere before using it.
    – Rahul Kumar
    Nov 10 at 19:54
















  • your layout xml file?
    – Ramees Thattarath
    Nov 10 at 19:28










  • That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
    – Mike M.
    Nov 10 at 19:30






  • 1




    you have used btnSearch but not initialized it anywhere before using it.
    – Rahul Kumar
    Nov 10 at 19:54















your layout xml file?
– Ramees Thattarath
Nov 10 at 19:28




your layout xml file?
– Ramees Thattarath
Nov 10 at 19:28












That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
– Mike M.
Nov 10 at 19:30




That code, as posted, will not compile. Please provide a Minimal, Complete, and Verifiable example. Furthermore, it's unclear exactly what the issue is. Please be specific.
– Mike M.
Nov 10 at 19:30




1




1




you have used btnSearch but not initialized it anywhere before using it.
– Rahul Kumar
Nov 10 at 19:54




you have used btnSearch but not initialized it anywhere before using it.
– Rahul Kumar
Nov 10 at 19:54












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You're overriding the wrong onCreate(), replace it with:



protected void onCreate(@Nullable Bundle savedInstanceState)


Edit: are you sure that this xml should be inflated in class SearchUser?
Do you have a class MainActivity like the xml states?






share|improve this answer






















  • Tried this but did not solve the problem :/
    – Franco Estevez
    Nov 10 at 19:49










  • see my edited answer
    – forpas
    Nov 10 at 19:53










  • Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
    – Franco Estevez
    Nov 10 at 20:17










  • So activity_main.xml is used for 2 activities?
    – forpas
    Nov 10 at 20:20










  • Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
    – Franco Estevez
    Nov 10 at 20:25

















up vote
0
down vote













Place the btnSearchUser button below the MapView in XML.



You've also configured MapView with match_parent, which is not applicable to a constraint layout parent. Set the height and width of MapView to 0dp as well.






share|improve this answer






















  • That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
    – Franco Estevez
    Nov 10 at 20:20










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242636%2fbutton-not-responding-to-onclick-method%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You're overriding the wrong onCreate(), replace it with:



protected void onCreate(@Nullable Bundle savedInstanceState)


Edit: are you sure that this xml should be inflated in class SearchUser?
Do you have a class MainActivity like the xml states?






share|improve this answer






















  • Tried this but did not solve the problem :/
    – Franco Estevez
    Nov 10 at 19:49










  • see my edited answer
    – forpas
    Nov 10 at 19:53










  • Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
    – Franco Estevez
    Nov 10 at 20:17










  • So activity_main.xml is used for 2 activities?
    – forpas
    Nov 10 at 20:20










  • Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
    – Franco Estevez
    Nov 10 at 20:25














up vote
0
down vote













You're overriding the wrong onCreate(), replace it with:



protected void onCreate(@Nullable Bundle savedInstanceState)


Edit: are you sure that this xml should be inflated in class SearchUser?
Do you have a class MainActivity like the xml states?






share|improve this answer






















  • Tried this but did not solve the problem :/
    – Franco Estevez
    Nov 10 at 19:49










  • see my edited answer
    – forpas
    Nov 10 at 19:53










  • Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
    – Franco Estevez
    Nov 10 at 20:17










  • So activity_main.xml is used for 2 activities?
    – forpas
    Nov 10 at 20:20










  • Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
    – Franco Estevez
    Nov 10 at 20:25












up vote
0
down vote










up vote
0
down vote









You're overriding the wrong onCreate(), replace it with:



protected void onCreate(@Nullable Bundle savedInstanceState)


Edit: are you sure that this xml should be inflated in class SearchUser?
Do you have a class MainActivity like the xml states?






share|improve this answer














You're overriding the wrong onCreate(), replace it with:



protected void onCreate(@Nullable Bundle savedInstanceState)


Edit: are you sure that this xml should be inflated in class SearchUser?
Do you have a class MainActivity like the xml states?







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 19:52

























answered Nov 10 at 19:37









forpas

4,3571216




4,3571216











  • Tried this but did not solve the problem :/
    – Franco Estevez
    Nov 10 at 19:49










  • see my edited answer
    – forpas
    Nov 10 at 19:53










  • Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
    – Franco Estevez
    Nov 10 at 20:17










  • So activity_main.xml is used for 2 activities?
    – forpas
    Nov 10 at 20:20










  • Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
    – Franco Estevez
    Nov 10 at 20:25
















  • Tried this but did not solve the problem :/
    – Franco Estevez
    Nov 10 at 19:49










  • see my edited answer
    – forpas
    Nov 10 at 19:53










  • Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
    – Franco Estevez
    Nov 10 at 20:17










  • So activity_main.xml is used for 2 activities?
    – forpas
    Nov 10 at 20:20










  • Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
    – Franco Estevez
    Nov 10 at 20:25















Tried this but did not solve the problem :/
– Franco Estevez
Nov 10 at 19:49




Tried this but did not solve the problem :/
– Franco Estevez
Nov 10 at 19:49












see my edited answer
– forpas
Nov 10 at 19:53




see my edited answer
– forpas
Nov 10 at 19:53












Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
– Franco Estevez
Nov 10 at 20:17




Yes I do have a class Main Activity, but does that mean that I cant use a button from the activity_main in another class?
– Franco Estevez
Nov 10 at 20:17












So activity_main.xml is used for 2 activities?
– forpas
Nov 10 at 20:20




So activity_main.xml is used for 2 activities?
– forpas
Nov 10 at 20:20












Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
– Franco Estevez
Nov 10 at 20:25




Yes, it should be. But I guess the problem is there. I have just investigated and in the xml file there is a line that says tools:context=".MainActivity". I think this has to do with the stuff that will work on that xml, and that is why its not working. Any idea?
– Franco Estevez
Nov 10 at 20:25












up vote
0
down vote













Place the btnSearchUser button below the MapView in XML.



You've also configured MapView with match_parent, which is not applicable to a constraint layout parent. Set the height and width of MapView to 0dp as well.






share|improve this answer






















  • That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
    – Franco Estevez
    Nov 10 at 20:20














up vote
0
down vote













Place the btnSearchUser button below the MapView in XML.



You've also configured MapView with match_parent, which is not applicable to a constraint layout parent. Set the height and width of MapView to 0dp as well.






share|improve this answer






















  • That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
    – Franco Estevez
    Nov 10 at 20:20












up vote
0
down vote










up vote
0
down vote









Place the btnSearchUser button below the MapView in XML.



You've also configured MapView with match_parent, which is not applicable to a constraint layout parent. Set the height and width of MapView to 0dp as well.






share|improve this answer














Place the btnSearchUser button below the MapView in XML.



You've also configured MapView with match_parent, which is not applicable to a constraint layout parent. Set the height and width of MapView to 0dp as well.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 1:03









Avery

4915




4915










answered Nov 10 at 19:58









Ramees Thattarath

186111




186111











  • That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
    – Franco Estevez
    Nov 10 at 20:20
















  • That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
    – Franco Estevez
    Nov 10 at 20:20















That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
– Franco Estevez
Nov 10 at 20:20




That shouldnt make sense, I also have two buttons on top of the mapview and they do work.
– Franco Estevez
Nov 10 at 20:20

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242636%2fbutton-not-responding-to-onclick-method%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3