Android second activity is ignoring xml file - java

In my second activity I have a textview that is not responding to the changes in the xml file, I'm trying to change the text size and alignment but nothing I do works, I can only guess that it because in the java file for the activity I have a .setText method changing the text of the textView and that's causing the program to ignore the xml file, my question is how to I now change the text size?
Java code:
package com.powermedia.rps;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by Joshua on 2/17/2015.
*/
public class ResultActivity extends ActionBarActivity implements View.OnClickListener
{
#Override
public void onCreate(Bundle savedInstanceState)
{
Button playAgainBtn;
TextView resulttv;
String userChoice = "";
String AndroidChoice = "";
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
playAgainBtn = (Button)findViewById(R.id.PlayAgain);
playAgainBtn.setOnClickListener(this);
resulttv = (TextView)findViewById(R.id.textView);
userChoice = this.getIntent().getExtras().getString("userChoice");
AndroidChoice = this.getIntent().getExtras().getString("AndroidChoice");
resulttv.setText("User chose " + userChoice + ", Android chose " + AndroidChoice +
"\n" + getWinner(AndroidChoice, userChoice) + " won!");
}
XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ffd3d3d3"
android:id="#+id/test">
<Space
android:layout_width="fill_parent"
android:layout_height="24dp"
android:id="#+id/space3"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="95dp"
android:layout_height="wrap_content"
android:text="Play Again"
android:id="#+id/PlayAgain"
android:layout_below="#+id/space3"
android:layout_centerHorizontal="true"
android:background="#ff959595" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="20dp"
android:textStyle="bold"
android:text="Tell who won or tie"
android:textAlignment="center" />

Change:
android:textSize="20dp"
to:
android:textSize="20sp"

Related

Android ID not found, when it is there

Android Studio is giving me errors in the Main Activity Java over unresolved symbols or id's. As far as I can see the id's refrenced in the java code exist.
In another app which used these same principles, it worked, I cross refrenced the two apps and could not find anything that stood out.
Here is my java code:
package com.example.android.quizapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
public class QuizMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_main);
}
public void display(int value) {
TextView quantityTextView = findViewById(R.id.value_text);
quantityTextView.setText(value);
}
public void slider(View view){
SeekBar seekBar = (SeekBar)findViewById(R.id.i);
int Value = seekBar.getProgress();
EditText text = (EditText)findViewById(R.id.valueText);
String name = text.getText().toString();
text.setText(Value);
}
}
Here is my XML: (The id's are there)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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="com.example.android.quizapplication.QuizMainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Quiz"
android:textAlignment="center"/>
<TextView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What is you favorite color?"
android:textAlignment="center"
android:paddingTop="20dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="#+id/title"
/>
<TextView
android:id="#+id/value_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="300dp"/>
<SeekBar
android:id="#+id/i"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:onClick="slider"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
Try adding this:
import com.example.android.quizapplication.R;

java.lang.IllegalStateException: Could not find method btnSubmit(View) in a parent or ancestor Context for android:onClick

This Java takes the inputs of Edit Text fields and outputs them into Toast.
I have no idea where or what the error is, any help would be greatly appreciated:
Java
package colonyapplication.colony;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class tenantReg extends Activity {
EditText fullName = (EditText) findViewById(R.id.etFname);
EditText userEmail = (EditText) findViewById(R.id.etEmail);
EditText userPass = (EditText) findViewById(R.id.etPass);
String fName = fullName.getText().toString();
String uEmail = userEmail.getText().toString();
String uPass = userPass.getText().toString();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tenant_reg);
}
public void btnSubmit() {
String tenant = "Tenant";
Toast.makeText(tenantReg.this, "UserName is: " + fName + ". Password is: " + uPass + "email is: " + uEmail + tenant, Toast.LENGTH_LONG).show();
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#fcdfaa"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="colonyapplication.colony.tenantReg">
<ImageView
android:id="#+id/imageView2"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/colonylogo"
android:layout_above="#+id/passTextBox"
android:layout_centerHorizontal="true"
android:layout_marginBottom="61dp" />
<EditText
android:id="#+id/etFname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageView2"
android:layout_alignStart="#+id/imageView2"
android:layout_below="#+id/imageView2"
android:ems="10"
android:hint="Full Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/etEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etFname"
android:layout_alignStart="#+id/etFname"
android:layout_centerVertical="true"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/etPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="29dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:layout_below="#+id/etEmail"
android:layout_alignStart="#+id/etEmail"
android:layout_alignEnd="#+id/etEmail" />
<EditText
android:id="#+id/etPassconfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="34dp"
android:ems="10"
android:hint="Confirm Password"
android:inputType="textPassword"
android:layout_below="#+id/etPass"
android:layout_alignStart="#+id/etPass"
android:layout_alignEnd="#+id/etPass" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="47dp"
android:background="#EE7600"
android:onClick="btnSubmit"
android:text="Submit"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="17sp"
android:layout_below="#+id/etPassconfirm"
android:layout_alignStart="#+id/etPassconfirm" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:background="#EE7600"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="17sp"
android:layout_alignBaseline="#+id/button"
android:layout_alignBottom="#+id/button"
android:layout_alignEnd="#+id/etPassconfirm"
android:layout_marginEnd="33dp" />
</RelativeLayout>
For whatever reason, when the submit button is clicked, the program stops in the emulator. The error in the Android Monitor states: "java.lang.IllegalStateException: Could not find method btnSubmit(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'button'"
As I see you have 2 Button but I dont know which one is submit button.
well also I can not find the meaning of public void btnSubmit(). As I know you should define tn submit:
Button btnSubmit = (Button) findViewById(R.id.your_btnSubmit_id);
and then use onClickListener method to do somthing when btn clicked
btnsubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Do somthing
}
});
Edit:
You can use your code just replace
public void btnSubmit()
with this:
public void btnSubmit(View v)

XML / Java Button Click to change TextView

I am realitavely new to Java coding and am trying to use a button press (in an Android App) to update a text view. The code I am currently using is causing my app to crash whenever I try to press the button.
Here is my XML
<LinearLayout>
<TextView
android:id="#+id/myTextView_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="calculateNewNumber"
android:text="Calculate New Number" />
</LinearLayout>
And Here is my Java
package com.example.android.myapp;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int startNumber = 0;
public void calculateNewNumber(View view) {
startNumber = startNumber + 1;
display(startNumber);
}
private void display(int number) {
TextView myTextView = (TextView) findViewById(
R.id.myTextView_text_view);
myTextView.setText("" + number);
}
}
Thanks for any help you can give.
The code itself works fine so the problem must be with your XML, assuming you have provided it in full here.
Using this XML, your MainActivity code works fine for me.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:id="#+id/myTextView_text_view"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="calculateNewNumber"
android:text="Calculate New Number" />
</LinearLayout>
</RelativeLayout>

Making android EditText vertical scrollable

I am new to Android development and I have an issue with making Android EditText vertically scroll able. The vertical scrolling of the EditText does not work for me. I followed several posts and resources but none of them worked for me.
I am using the following code sample to enable the vertical scroll ability.
this.detailsEditText.setScroller(new Scroller(this));
this.detailsEditText.setMaxLines(1);
this.detailsEditText.setVerticalScrollBarEnabled(true);
this.detailsEditText.setMovementMethod(new ScrollingMovementMethod());
The following are the activity class and layout resource file, respectively I am using in my app.
CreateAppointmentActivity.java
package lk.iit.appointmentmanagerapp.activities;
import java.sql.Date;
import java.sql.Time;
import lk.iit.appointmentmanagerapp.data.Appointment;
import lk.iit.appointmentmanagerapp.data.DatabaseHandler;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Scroller;
public class CreateAppointmentActivity extends Activity {
private EditText titleEditText;
private EditText timeEditText;
private EditText detailsEditText;
private EditText dateEditText;
private Button saveButton;
private Button resetButton;
private final DatabaseHandler handler = new DatabaseHandler(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_appointment);
this.titleEditText = (EditText)(this.findViewById(R.id.edit_title));
this.timeEditText = (EditText)(this.findViewById(R.id.edit_time));
this.detailsEditText = (EditText)(this.findViewById(R.id.edit_details));
this.dateEditText = (EditText)(this.findViewById(R.id.edit_date));
this.detailsEditText.setScroller(new Scroller(this));
this.detailsEditText.setMaxLines(1);
this.detailsEditText.setVerticalScrollBarEnabled(true);
this.detailsEditText.setMovementMethod(new ScrollingMovementMethod());
SharedPreferences preferences = getSharedPreferences("date_variables", MODE_PRIVATE);
this.dateEditText.setText(preferences.getInt("Year", 0) + "-" + preferences.getInt("Month", 0) + "-" + preferences.getInt("Day", 0));
this.dateEditText.setEnabled(false);
this.saveButton = (Button)(this.findViewById(R.id.save_new_appointment_button));
this.saveButton.setOnClickListener(new View.OnClickListener() {
#SuppressWarnings("deprecation")
#Override
public void onClick(View v) {
String[] dateComponents = dateEditText.getText().toString().split("-");
String[] timeComponents = timeEditText.getText().toString().split(":");
Appointment appointment = new Appointment();
appointment.setAppointment_title(titleEditText.getText().toString());
appointment.setAppointment_date(new Date(Integer.parseInt(dateComponents[0]), Integer.parseInt(dateComponents[1]), Integer.parseInt(dateComponents[2])));
appointment.setAppointment_time(new Time(Integer.parseInt(timeComponents[0]), Integer.parseInt(timeComponents[1]), Integer.parseInt(timeComponents[2])));
appointment.setAppointment_details(detailsEditText.getText().toString());
boolean inserted = handler.addAppointment(appointment);
//
//
}
});
this.resetButton = (Button)(this.findViewById(R.id.reset_button));
this.resetButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
titleEditText.setText("");
timeEditText.setText("");
detailsEditText.setText("");
dateEditText.setText("");
}
});
}
}
activity_create_appointment.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/background"
tools:context="lk.iit.appointmentmanagerapp.activities.CreateAppointmentActivity" >
<TextView
android:id="#+id/create_activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_create"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:textSize="18.5sp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/create_activity_title"
android:layout_marginTop="15dip"
android:text="#string/title_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/create_activity_title"
android:layout_marginTop="15dip"
android:layout_toRightOf="#+id/title_textview"
android:layout_marginLeft="30dip"
android:background="#ffffff"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/time_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title_textview"
android:layout_marginTop="25dip"
android:text="#string/time_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText
android:id="#+id/edit_time"
android:background="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/time_textview"
android:layout_below="#+id/edit_title"
android:layout_marginLeft="25dip"
android:layout_marginTop="25dip"
android:ems="10"
android:inputType="time" />
<TextView
android:id="#+id/details_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/time_textview"
android:text="#string/details_textview_text"
android:layout_marginTop="25dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/details_textview"
android:layout_alignBottom="#+id/details_textview"
android:layout_alignLeft="#+id/edit_title"
android:background="#ffffff"
android:ems="10"
android:inputType="text" >
</EditText>
<TextView
android:id="#+id/date_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/details_textview"
android:text="Date"
android:layout_marginTop="25dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/date_textview"
android:layout_below="#+id/edit_details"
android:background="#ffffff"
android:layout_marginLeft="25dip"
android:layout_marginTop="25dip"
android:ems="10"
android:inputType="date" >
</EditText>
<Button
android:id="#+id/save_new_appointment_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/date_textview"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
android:layout_centerHorizontal="true"
android:text="#string/save_button_text"
android:textAllCaps="false" />
<Button
android:id="#+id/reset_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/save_new_appointment_button"
android:layout_marginTop="2dip"
android:layout_centerHorizontal="true"
android:text="#string/reset_button_text"
android:textAllCaps="false" />
</RelativeLayout>
Please bear with me if I have done any mistakes as I am relatively new to this area of development.
I would be grateful if someone help me out with this issue.
Try this in java code:
EditText dwEdit = (EditText) findViewById(R.id.DwEdit);
dwEdit.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (view.getId() ==R.id.DwEdit) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
And in your xml:
<EditText
android:id="#+id/DwEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="10"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
android:inputType="textCapSentences">
</EditText>
If you wanna scroll editText only in detailEditText then you specify height of editText 50dp or your need and remove inputType="text" from your editText ....it fulfill your need..
and you don't need any code in java relative to that editText..

Unable to run code for Simple Counter App for Android

I am trying to make an application on Android Studio with the help of a tutorial. I managed to get the User Interface right and I think that I have assigned the correct buttons too. I am unable to get where I am going wrong with my code. I am new to Java and so I am unable to pinpoint the error I have committed. I am posting below the code from the files I was asked to edit in the tutorial.
package com.example.to_dolistapplication.app;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.Color;
public class MainActivity extends Activity implements OnClickListener {
Button btn1;
Button btn2;
Button btn3;
TextView textTitle;
EditText scoreText;
int counter = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.button);
btn2 = (Button)findViewById(R.id.button2);
btn3 = (Button)findViewById(R.id.button3);
scoreText = (EditText)findViewById(R.id.textView);
textTitle = (TextView)findViewById(R.id.editText);
//---set on click listeners on the buttons-----
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
// change font size of the text
textTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
}
#Override
public void onClick(View v) {
if (v == btn1){
counter++;
scoreText.setText(Integer.toString(counter));
scoreText.setBackgroundColor(Color.CYAN);
}
if (v == btn2){
counter--;
scoreText.setText(Integer.toString(counter));
scoreText.setBackgroundColor(Color.GREEN);
}
if (v == btn3){
counter = 0;
scoreText.setText(Integer.toString(counter));
scoreText.setBackgroundColor(Color.RED);
}
}
}
Above is the File from MainActivity.java
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.to_dolistapplication.app.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+1"
android:id="#+id/button"
android:onClick="#string/intro"
android:layout_below="#+id/editText"
android:layout_toRightOf="#+id/textView"
android:layout_marginTop="79dp"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1"
android:id="#+id/button2"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/button"
android:layout_alignStart="#+id/button"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:id="#+id/button3"
android:layout_below="#+id/button2"
android:layout_marginTop="64dp"
android:layout_alignRight="#+id/button2"
android:layout_alignEnd="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_alignStart="#+id/button2" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textClock"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/textView2"
android:layout_alignBottom="#+id/textView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editText"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Score"
android:id="#+id/textView"
android:layout_alignBottom="#+id/editText"
android:layout_toLeftOf="#+id/editText" />
This is from the file activity_main.xml.
The app, when run on emulator, displays Unfortunately Counter App has stopped.
what might be the reason for the app not working? Please help.
**EditText** scoreText = (EditText)findViewById(R.id.textView);
**TextView** textTitle = (TextView)findViewById(R.id.editText);
you missmathed with types: android:id="#+id/editText" is EditText, but in Activity you wrote his id to TextView.
And you missmathed with types: android:id="#+id/textView" is TextView, but but in Activity you wrote his id as EditText.
You've mismatched id's in onCreate() method.
Use the debug mode or just look at your console output

Categories