Button not respond to on click event

Button not respond to on click event

Need to hire an IT company?

Post your project

in 5 minutes for free

ShaharTech

Button not respond to on click event

on Android Developers at Dec 21, 2017 19:23

I'm trying for hours to make the button click but for some weird reason it doesnt work. I have the main activity and from there I set the content view to first run activity and this is the code of the first run activity

import android.app.Activity;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class FirstRun extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_run);
final Button button = (Button) findViewById(R.id.nextBtn);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("Test","test");
System.out.println("Button one is pressed");
button.setText("Test");
//Get edit text values
EditText nameET = (EditText) findViewById(R.id.Name);
EditText ageET = (EditText) findViewById(R.id.Age);
EditText emailET = (EditText) findViewById(R.id.Email);
EditText phoneET = (EditText) findViewById(R.id.Phone);
//set data in the info
//info = new UserInfo(nameET.getText().toString(),emailET.getText().toString(),phoneET.getText().toString());
if (nameET.getText().toString() != "" && ageET.getText().toString() != "" && emailET.getText().toString() != "" && phoneET.getText().toString() != "") {
SharedPreferences settings = getSharedPreferences("UserInfo", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("Name", nameET.getText().toString());
editor.putString("Email", emailET.getText().toString());
editor.putString("Phone", phoneET.getText().toString());
editor.putInt("Age", Integer.parseInt(ageET.getText().toString()));
}
}
});
}
}

Xml Layout details about the layout of the app and the button i tried to add to the button onclick event on xml but every time I did it the app just crush and didn't respond at all

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp"
android:background="@drawable/backgroundimage">

<TextView
android:id="@+id/WelcomeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/welcome_to_my_app"
android:textColor="@android:color/background_dark"
android:textSize="24sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="10dp" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/please_fill_the_information"
android:textColor="@android:color/holo_blue_dark"
android:textSize="20sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="10dp" />
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="3"
android:rowCount="7">


<TextView
android:id="@+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="2"
android:text="@string/name"
android:textColor="@color/colorAccent"
android:textSize="18sp" />

<EditText
android:id="@+id/Name"
style="@style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:capitalize="sentences"
android:ems="14"
android:inputType="textPersonName"
android:visibility="visible" />

<TextView
android:id="@+id/phoneTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="3"
android:text="@string/phone"
android:textColor="@color/colorAccent"
android:textSize="18sp" />

<EditText
android:id="@+id/Phone"
style="@style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:ems="14"
android:inputType="phone"
android:visibility="visible" />

<TextView
android:id="@+id/emailTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="4"
android:text="@string/email"
android:textColor="@color/colorAccent"
android:textSize="18sp" />

<EditText
android:id="@+id/Email"
style="@style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="4"
android:ems="14"
android:inputType="textEmailAddress"
android:visibility="visible" />

<TextView
android:id="@+id/ageTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="5"
android:text="@string/age"
android:textColor="@color/colorAccent"
android:textSize="18sp" />

<EditText
android:id="@+id/Age"
style="@style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="5"
android:ems="14"
android:inputType="number"
android:visibility="visible" />


</GridLayout>

<Button
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@android:color/holo_blue_dark"
android:text="@string/next" />
</LinearLayout>
Jaenelle Isidro

Re: Button not respond to on click event

on Android Developers at Jan 09, 2018 18:46

any error logs?
HokuApps123

Re: Button not respond to on click event

on Android Developers at Jan 11, 2018 08:21

Yes it is helpful if you share an error report if any as the code looks ideal.
sophie

Re: Button not respond to on click event

on Android Developers at Jan 11, 2018 10:06

hey there! I see your code but you don't give what error occurred in your code.
whatever, you can check this code. maybe it will help you.

createMyButton = function(data) {

var button = $('<div id="my-button"></div>')
.css({
'display' : 'inline',
'padding' : '0px 2px 2px 0px',
'cursor' : 'pointer'
}).append($('<a>').attr({
//'href' : Share.serializeJson(data),
'target' : '_blank',
'rel' : 'nofollow'
}).append($('<image src="css/images/Facebook-icon.png">').css({
"padding-top" : "0px",
"margin-top" : "0px",
"margin-bottom" : "0px"
})));

button.click(function () {
console.log("asdfasdf");
});

return button;
}
This forum thread discusses Button not respond to on click event. You can join the discussion by clicking on 'Post a reply'. If you are new to Android Developers Forum, you will need to sign up and create a new account.

Button not respond to on click event related posts on Android Developers Forum

build an app for learning language

by aucun on Android Developers

Can Android Take Over iOS ?

by on Android Developers

Can you give advice?

by Domashno on Android Developers

Reply on this threadPost a reply
Loading...