I am trying to create an ImageButton and use it for adding a new note.
But when I click on that ImageButton, a message appears (Failed) without mentioning the reason for the failure.
The xml layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#color/my_primary"
android:padding="16dp"
tools:context=".NoteDetailsActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/title_bar_layout">
<TextView
android:id="#+id/page_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add New Note"
android:textColor="#color/white"
android:textSize="32sp"
android:textStyle="bold" />
<ImageButton
android:layout_width="36dp"
android:layout_height="36dp"
android:id="#+id/save_note_btn"
android:src="#drawable/ic_baseline_done_24"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
app:tint="#color/white"
android:background="?attr/selectableItemBackgroundBorderless"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_bar_layout"
android:orientation="vertical"
android:padding="16dp"
android:layout_marginVertical="26dp"
android:backgroundTint="#color/white"
android:background="#drawable/rounded_corner">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/notes_title_text"
android:hint="Title"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginVertical="8dp"
android:padding="12dp"
android:textColor="#color/black"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/notes_content_text"
android:hint="Content"
android:minLines="15"
android:gravity="top"
android:textSize="20sp"
android:layout_marginVertical="8dp"
android:padding="12dp"
android:textColor="#color/black"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/delete_note_text_view_btn"
android:text="Delete note"
android:layout_alignParentBottom="true"
android:gravity="center"
android:textSize="18sp"
android:visibility="gone"
android:textColor="#FF0000"/>
And this is my Activity class:
package easy.tuto.notespro;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.DocumentReference;
public class NoteDetailsActivity extends AppCompatActivity {
EditText titleEditText,contentEditText;
ImageButton saveNoteBtn;
TextView pageTitleTextView;
String title,content,docId;
boolean isEditMode = false;
TextView deleteNoteTextViewBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_details);
titleEditText = findViewById(R.id.notes_title_text);
contentEditText = findViewById(R.id.notes_content_text);
saveNoteBtn = findViewById(R.id.save_note_btn);
pageTitleTextView = findViewById(R.id.page_title);
deleteNoteTextViewBtn = findViewById(R.id.delete_note_text_view_btn);
//receive data
title = getIntent().getStringExtra("title");
content= getIntent().getStringExtra("content");
docId = getIntent().getStringExtra("docId");
if(docId!=null && !docId.isEmpty()){
isEditMode = true;
}
titleEditText.setText(title);
contentEditText.setText(content);
if(isEditMode){
pageTitleTextView.setText("Edit your note");
deleteNoteTextViewBtn.setVisibility(View.VISIBLE);
}
saveNoteBtn.setOnClickListener( (v)-> saveNote());
deleteNoteTextViewBtn.setOnClickListener((v)-> deleteNoteFromFirebase() );
}
void saveNote(){
String noteTitle = titleEditText.getText().toString();
String noteContent = contentEditText.getText().toString();
if(noteTitle==null || noteTitle.isEmpty() ){
titleEditText.setError("Title is required");
return;
}
Note note = new Note();
note.setTitle(noteTitle);
note.setContent(noteContent);
note.setTimestamp(Timestamp.now());
saveNoteToFirebase(note);
}
void saveNoteToFirebase(Note note){
DocumentReference documentReference;
if(isEditMode){
//update the note
documentReference = Utility.getCollectionReferenceForNotes().document(docId);
}else{
//create new note
documentReference = Utility.getCollectionReferenceForNotes().document();
}
documentReference.set(note).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
//note is added
Utility.showToast(NoteDetailsActivity.this,"Note added successfully");
finish();
}else{
Utility.showToast(NoteDetailsActivity.this,"Failed while adding note");
}
}
});
}
void deleteNoteFromFirebase(){
DocumentReference documentReference;
documentReference = Utility.getCollectionReferenceForNotes().document(docId);
documentReference.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
//note is deleted
Utility.showToast(NoteDetailsActivity.this,"Note deleted successfully");
finish();
}else{
Utility.showToast(NoteDetailsActivity.this,"Failed while deleting note");
}
}
});
}
}
Please help me find out the reason and how to solve the problem, thank you.
Related
I am implementing an OTP Verification system and have 3 EditText fields in my layout, and one of them is hidden until the user clicks a button.
Here is the layout file:
registration_acivity_xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".RegistrationActivity">
<ImageView
/>
<TextView
/>
<TextView
/>
<TextView
/>
<EditText
android:id="#+id/mobile"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_below="#+id/regText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:clickable="true"
android:focusable="true"
android:hint="Enter Mobile Number"
android:inputType="phone"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/regText" />
<EditText
android:id="#+id/pin_code"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="#+id/mobile"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:autofillHints="Enter Area Pin Code"
android:clickable="true"
android:focusable="true"
android:hint="Enter Area Pin Code"
android:inputType="number"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="15sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mobile" />
<TextView
android:id="#+id/verify_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/pin_code"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Verify mobile number with OTP"
android:textAlignment="center"
android:textColor="#696969"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/pin_code" />
<Button
android:id="#+id/get_otp_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/verify_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:alpha="1"
android:backgroundTint="#00FA9A"
android:text="Get OTP"
android:textAlignment="center"
android:textColor="#696969"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/verify_text" />
<EditText
android:id="#+id/gen_otp"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="#+id/verify_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:alpha="0"
android:clickable="true"
android:focusable="true"
android:hint="Enter OTP"
android:inputType="number"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="15sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/verify_text" />
<Button
android:id="#+id/verify_otp_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/get_otp_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:alpha="0"
android:backgroundTint="#00FA9A"
android:text="Verify OTP"
android:textAlignment="center"
android:textColor="#696969"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gen_otp" />
</androidx.constraintlayout.widget.ConstraintLayout>
The problem I am having is that when the third otp EditText is shown it doesn't show the virtual keyboard or gets focused when clicked. Instead I have to first click one of the previous two EditTexts for it to show the virtual keyboard.
What can I do to make the virtual keyboard show on clicking the OTP field at once?
Here is the java file.
RegistrationActivity.java:
package com.example.covislot;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.FirebaseException;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;
import java.util.concurrent.TimeUnit;
public class RegistrationActivity extends AppCompatActivity {
EditText mobileField, pinField,otpField;
Button getOTP, verifyOTP;
String mobileNumber, pinCode, OTP;
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallback;
FirebaseAuth auth;
private String verificationCode;
SharedPreferences sp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration_activity);
sp = getSharedPreferences("login",MODE_PRIVATE);
StartFirebaseLogin();
mobileField = findViewById(R.id.mobile);
pinField = findViewById(R.id.pin_code);
otpField = findViewById(R.id.gen_otp);
getOTP = findViewById(R.id.get_otp_button);
verifyOTP = findViewById(R.id.verify_otp_button);
getOTP.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (TextUtils.isEmpty(mobileField.getText().toString())) {
// when mobile number field is empty
// displaying a toast message.
Toast.makeText(RegistrationActivity.this, "Please enter a valid phone number.", Toast.LENGTH_SHORT).show();
} else {
mobileNumber = "+91" + mobileField.getText().toString();
}
if (TextUtils.isEmpty(pinField.getText().toString())) {
// when pin number field is empty
// displaying a toast message.
Toast.makeText(RegistrationActivity.this, "Please enter a valid Pin code.", Toast.LENGTH_SHORT).show();
} else {
pinCode = pinField.getText().toString();
}
PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(auth)
.setPhoneNumber(mobileNumber) // Phone number to verify
.setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(RegistrationActivity.this) // Activity (for callback binding)
.setCallbacks(mCallback) // OnVerificationStateChangedCallbacks
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
}
});
verifyOTP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (TextUtils.isEmpty(otpField.getText().toString())) {
// when otp field is empty
// displaying a toast message.
Toast.makeText(RegistrationActivity.this, "Please enter a valid OTP.", Toast.LENGTH_SHORT).show();
} else {
OTP = otpField.getText().toString();
}
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode, OTP);
SigninWithPhone(credential);
}
});
}
private void SigninWithPhone(PhoneAuthCredential credential) {
auth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
sp.edit().putBoolean("logged", true).apply();
sp.edit().putString("phone", mobileNumber).apply();
sp.edit().putString("pinCode", pinCode).apply();
startActivity(new Intent(RegistrationActivity.this,SignedInActivity.class));
finish();
} else {
Toast.makeText(RegistrationActivity.this,"Incorrect OTP",Toast.LENGTH_SHORT).show();
}
}
});
}
private void StartFirebaseLogin() {
auth = FirebaseAuth.getInstance();
mCallback = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(RegistrationActivity.this,"verification completed",Toast.LENGTH_SHORT).show();
}
#Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(RegistrationActivity.this,"verification failed",Toast.LENGTH_SHORT).show();
}
#Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationCode = s;
Toast.makeText(RegistrationActivity.this,"Code sent",Toast.LENGTH_SHORT).show();
getOTP.animate().alpha(0f).setDuration(500);
otpField.setVisibility(View.VISIBLE);
otpField.animate().alpha(1f).setDuration(500);
verifyOTP.setVisibility(View.VISIBLE);
verifyOTP.animate().alpha(1f).setDuration(600);
}
};
}
}
Put this line when you want to give it focus:
otpField.requestFocus();
Also, to show the soft keyboard explicitly, you can do like below:
otpField.postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager im = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(otpField, InputMethodManager.SHOW_IMPLICIT);
}
},200);
I am new to android, i was following some tutorial and at this point, app keeps crashing when i click the login button.
When i run the app and click the login button, the app crashes and in the logcat, it shows this error of java RuntimeException.
This is my logcat, loginactivity.xml and loginactivity.java.
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.ugtunda/com.example.ugtunda.LoginActivity}:
java.lang.ClassCastException:
androidx.appcompat.widget.AppCompatTextView cannot be cast to
com.rey.material.widget.TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2806)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2884)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1614)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
Caused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatTextView cannot be cast to
com.rey.material.widget.TextView
at com.example.ugtunda.LoginActivity.onCreate(LoginActivity.java:48)
at android.app.Activity.performCreate(Activity.java:7044)
at android.app.Activity.performCreate(Activity.java:7035)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2759)
Here is my login_activity_XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
android:background="#drawable/login"
tools:context=".LoginActivity">
<ImageView
android:id="#+id/login_applogo"
android:layout_width="300dp"
android:layout_height="100dp"
android:src="#drawable/applogo"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
/>
<EditText
android:id="#+id/login_phone_number_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/login_applogo"
android:background="#drawable/input_design"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:hint="Phone Number"
android:inputType="number"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="17sp"
android:textStyle="bold"
/>
<EditText
android:id="#+id/login_password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/login_phone_number_input"
android:background="#drawable/input_design"
android:padding="20dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="17sp"
android:textStyle="bold"
/>
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/login_password_input"
android:layout_marginTop="5dp"
>
<com.rey.material.widget.CheckBox
android:id="#+id/remember_me_chkb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Material.Drawable.CheckBox"
android:text="Remember Me"
android:textColor="#color/colorPrimaryDark"
app:cbd_strokeColor="#color/colorPrimaryDark"
android:gravity="center_vertical"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginLeft="17dp"
/>
<TextView
android:id="#+id/forget_password_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forget Password"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
/>
</LinearLayout>
<Button
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linear_layout_1"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#drawable/buttons"
android:padding="17dp"
android:text="Login"
android:textAllCaps="false"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/admin_panel_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/login_button"
android:layout_alignParentEnd="true"
android:layout_marginLeft="80dp"
android:layout_marginEnd="23dp"
android:text="I'm an Admin"
android:textAppearance="#android:style/TextAppearance.Material.Small"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/not_admin_panel_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm not an Admin"
android:layout_alignParentStart="true"
android:layout_below="#+id/login_button"
android:textColor="#color/colorPrimaryDark"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
android:layout_marginEnd="23dp"
android:layout_marginStart="25dp"
android:visibility="invisible"
/>
</RelativeLayout>
And lastly my loginactivity.java
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.ugtunda.Models.Users;
import com.example.ugtunda.Prevalent.Prevalent;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rey.material.widget.CheckBox;
import com.rey.material.widget.TextView;
import io.paperdb.Paper;
public class LoginActivity extends AppCompatActivity
{
private EditText InputPhoneNumber, InputPassword;
private Button LoginButton;
private ProgressDialog loadingBar;
private TextView AdminLink, NotAdminLink;
private String parentDbName = "Users";
private CheckBox chkBoxRememberMe;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
LoginButton = findViewById(R.id.login_button);
InputPassword = findViewById(R.id.login_password_input);
InputPhoneNumber = findViewById(R.id.login_phone_number_input);
AdminLink = findViewById(R.id.admin_panel_link);
NotAdminLink = findViewById(R.id.not_admin_panel_link);
loadingBar = new ProgressDialog(this);
chkBoxRememberMe = findViewById(R.id.remember_me_chkb);
Paper.init(this);
LoginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
LoginUser();
}
});
AdminLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
LoginButton.setText("Login Admin");
AdminLink.setVisibility(View.INVISIBLE);
NotAdminLink.setVisibility(View.VISIBLE);
parentDbName = "Admins";
}
});
NotAdminLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
LoginButton.setText("Login");
AdminLink.setVisibility(View.VISIBLE);
NotAdminLink.setVisibility(View.INVISIBLE);
parentDbName = "Users";
}
});
}
private void LoginUser()
{
String phone = InputPhoneNumber.getText().toString();
String password = InputPassword.getText().toString();
if (TextUtils.isEmpty(phone))
{
Toast.makeText(this, "Please write your phone number...", Toast.LENGTH_SHORT).show();
}
else if (TextUtils.isEmpty(password))
{
Toast.makeText(this, "Please write your password...", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Login Account");
loadingBar.setMessage("Please wait, while we are checking the credentials.");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
AllowAccessToAccount(phone, password);
}
}
private void AllowAccessToAccount(final String phone, final String password)
{
if(chkBoxRememberMe.isChecked())
{
Paper.book().write(Prevalent.USER_PHONE_KEY, phone);
Paper.book().write(Prevalent.USER_PASSWORD_KEY, password);
}
final DatabaseReference RootRef;
RootRef = FirebaseDatabase.getInstance().getReference();
RootRef.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot)
{
if (dataSnapshot.child(parentDbName).child(phone).exists())
{
Users usersData = dataSnapshot.child(parentDbName).child(phone).getValue(Users.class);
if (usersData.getPhone().equals(phone))
{
if (usersData.getPassword().equals(password))
{
if (parentDbName.equals("Admins"))
{
Toast.makeText(LoginActivity.this, "Welcome Admin, you are logged in Successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent intent = new Intent(LoginActivity.this, AdminCategoryActivity.class);
startActivity(intent);
}
else if (parentDbName.equals("Users"))
{
Toast.makeText(LoginActivity.this, "logged in Successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
Prevalent.currentOnlineUser = usersData;
startActivity(intent);
}
}
else
{
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "Password is incorrect.", Toast.LENGTH_SHORT).show();
}
}
}
else
{
Toast.makeText(LoginActivity.this, "Account with this " + phone + " number do not exists.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
It looks like you're defining standard Android components in the XML layout, then attempting to inflate them into custom components (the com.rey.material package). Try going into your imports and deleting the com.rey.material lines. Then when your IDE prompts you to import the TextView and Checkbox, make sure you're importing the versions from android.widget, not com.rey.material. Alternatively, you could change your XML file to specify the com.rey.material components if you wanted to be using those instead of the default ones.
You used the wrong import so you need to
replace this import
import com.rey.material.widget.TextView;
with
import android.widget.TextView;
OR
You can use the corresponding view in the XML
Replace
<TextView
android:id="#+id/forget_password_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forget Password"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginLeft="80dp"
/>
with
<com.rey.material.widget.TextView
android:id="#+id/forget_password_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forget Password"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginLeft="80dp" />
in your XML file
Looks like you are using the AppCompat Button in your XML, but using the material button in your java code.
So they need to be the same.
First you need to use the right import for whatever view you're using, if you want to use the AppCompat button then import like this
import android.widget.Button;
If you want to use the Material button, then use this import:
import com.rey.material.widget.Button;
Same thing goes for the TextView.
Hope this helps!
androidx.appcompat.widget.AppCompatTextView cannot be cast to
com.rey.material.widget.TextView
In your xml, you're using the SDK TextView but in your code, you want the com.rey.material.widget one.
--> Change one of these
My android app includes a true/false game.
The user should click either the true or false image one time and the next statement will appear.
I need the user to click the image only once, but it is only allowing for double clicks.
Is there anyway to set the clicks to be single rather than double?
I have checked that the focusable and focusable in touch attributes are null
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#B5FFFFFF"
android:orientation="vertical"
tools:context=".industry_standards_questions">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:background="#63FFFFFF">
<TextView
android:layout_width="420dp"
android:layout_height="150dp"
android:gravity="center"
android:text="Know your standards"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#0C40F1"
android:textSize="40dp"
android:textStyle="bold">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.38">
<TextView
android:id="#+id/statement_TV"
android:layout_width="420dp"
android:layout_height="150dp"
android:gravity="center"
android:text="Statement"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#020202"
android:textSize="20dp"
android:textStyle="bold">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.38"
android:background="#00FFFFFF">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:weightSum="2">
<ImageView
android:id="#+id/trueImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginRight="20dp"
android:src="#drawable/true_button"></ImageView>
<ImageView
android:id="#+id/falseImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:focusableInTouchMode="true"
android:src="#drawable/false_button"></ImageView>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.38">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:padding="20dp"
>
<Button
android:id="#+id/finish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:text="Finish"
android:textColor="#050505"
android:background="#E4DABC53"
android:textSize="20dp"
android:textStyle="bold"
>
</Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
package com.example.securityapp;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewAnimator;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.Collections;
public class industry_standards_questions extends AppCompatActivity {
DatabaseReference databaseUsers;
FirebaseDatabase database = FirebaseDatabase.getInstance();
FirebaseAuth mAuth;
TextView stmnt;
ImageView image_true, image_false;
Button points;
Statements tfStatements;
int statementsLength;
ArrayList<Item> statementList;
int currentStatement = 0;
int grade = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_industry_standards_questions);
databaseUsers = database.getReference();
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
stmnt = (TextView) findViewById(R.id.statement_TV);
image_true = (ImageView) findViewById(R.id.trueImage);
image_false = (ImageView) findViewById(R.id.falseImage);
tfStatements = new Statements();
statementsLength = tfStatements.tfStatements.length;
statementList = new ArrayList<>();
points = (Button) findViewById(R.id.final_score);
for(int i = 0; i < statementsLength; i++){
statementList.add(new Item(tfStatements.getStatement(i), tfStatements.getAnswer(i)));
}
Collections.shuffle(statementList);
setStmnt(currentStatement);
image_true.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (checkAnswer(currentStatement)) {
grade++;
if (currentStatement < statementsLength - 1)
setStmnt(currentStatement);
}
currentStatement++;
if(currentStatement >= statementsLength) { score(); }
}
});
image_false.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!checkAnswer(currentStatement)){
grade++;
if(currentStatement < statementsLength -1)
setStmnt(currentStatement);
}
currentStatement++;
if(currentStatement >= statementsLength) { score(); }
}
});
}
// show Statement
private void setStmnt(int number){
stmnt.setText(statementList.get(number).getStatement());
}
//check is answer is right
private boolean checkAnswer(int number){
String answer = statementList.get(number).getAnswer();
return answer.equals("true");
}
public void score(){
Users.currentUser.setScore(grade);
databaseUsers.child(Users.currentUserId).setValue(Users.currentUser);
Toast.makeText(this, "You scored " + grade + " points!", Toast.LENGTH_LONG).show();
grade = 0;
}
}
You can set your view to not be focusable with view.setFocusable(false), because if they are focusable, the first touch will "focus" them (which has no effects on ImageViews) and the second will call the onClick()-method.
If it is set to false, you will just need one click to call your onClick()-method.
Clicking on register makes the app crash when the email and password fields are empty, but when the name field is empty it works properly what seems to be the problem?
xml file:
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.zachmarcelo.softcash.LoginActivity"
android:background="#fff"
>
<!-- Login progress -->
<ImageView
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginBottom="20dp"
android:visibility="visible"
app:srcCompat="#drawable/icon_ewallet_" />
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="#color/colorHint" >
<EditText
android:id="#+id/reg_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="text"
android:textSize="20sp"
android:textColor="#android:color/background_dark"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel"
android:textColorHint="#color/colorHint">
<EditText
android:id="#+id/reg_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#android:color/darker_gray"
android:hint="Email"
android:maxLines="1"
android:singleLine="true"
android:textColor="#android:color/background_dark"
android:inputType="textEmailAddress"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel"
android:textColorHint="#color/colorHint">
<EditText
android:id="#+id/reg_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#android:color/background_dark"
android:hint="Password"
android:imeActionId="6"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:textColor="#android:color/background_dark" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/register"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#color/colorAccent"
android:gravity="center"
android:paddingLeft="20sp"
android:paddingRight="20sp"
android:text="Register"
android:textStyle="bold"
android:layout_marginBottom="20dp"/>
<TextView
android:id="#+id/signin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Already have an account?"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="12dp" />
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
code:
package com.example.zachmarcelo.softcash;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.view.WindowManager;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
public class RegisterActivity extends AppCompatActivity implements
View.OnClickListener {
private EditText reg_password,
reg_username,
reg_email;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
progressBar = new ProgressBar(getApplicationContext());
reg_password = findViewById(R.id.reg_password);
reg_email = findViewById(R.id.reg_email);
reg_username = findViewById(R.id.reg_username);
progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
mAuth = FirebaseAuth.getInstance();
findViewById(R.id.register).setOnClickListener(this);
findViewById(R.id.signin).setOnClickListener(this);
}
#Override
protected void onStart() {
super.onStart();
if (mAuth.getCurrentUser() != null) {
Intent i = new Intent(RegisterActivity.this, HomeActivity.class);
startActivity(i);
finish();
}
}
private void registerUser() {
final String username = reg_username.getText().toString().trim();
final String email = reg_email.getText().toString().trim();
String password = reg_password.getText().toString().trim();
if (username.equals("")) {
reg_username.setError(getString(R.string.input_error_name));
reg_username.requestFocus();
return;
}
if (email.equals("")) {
reg_email.setError(getString(R.string.input_error_email));
reg_email.requestFocus();
return;
}else{
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
reg_email.setError(getString(R.string.input_error_email_invalid));
reg_email.requestFocus();
return;
}
}
if (password.equals("")) {
reg_password.setError(getString(R.string.input_error_password));
reg_password.requestFocus();
return;
}else{
if (password.length() < 8) {
reg_password.setError(getString(R.string.input_error_password_length));
reg_password.requestFocus();
return;
}
}
progressBar.setVisibility(View.VISIBLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
User user = new User(
username,
email
);
FirebaseDatabase.getInstance().getReference("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
progressBar.setVisibility(View.GONE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
if (task.isSuccessful()) {
Toast.makeText(RegisterActivity.this, getString(R.string.registration_success), Toast.LENGTH_LONG).show();
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(i);
finish();
} else {
Toast.makeText(RegisterActivity.this, getString(R.string.registration_failed), Toast.LENGTH_LONG).show();
}
}
});
} else {
Toast.makeText(RegisterActivity.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.register:
registerUser();
break;
case R.id.signin:
Intent i = new Intent(this, LoginActivity.class);
startActivity(i);
finish();
break;
}
}
}
error log:
09-03 13:25:24.942 15875-15875/com.example.zachmarcelo.softcash E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.zachmarcelo.softcash, PID: 15875
android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class TextView
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 4: TypedValue{t=0x2/d=0x1010099 a=1}
at android.content.res.TypedArray.getColor(TypedArray.java:492)
at android.widget.TextView.<init>(TextView.java:955)
at android.widget.TextView.<init>(TextView.java:872)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:75)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.widget.Editor.showError(Editor.java:505)
at android.widget.Editor.onFocusChanged(Editor.java:1237)
at android.widget.TextView.onFocusChanged(TextView.java:9821)
at android.view.View.handleFocusGainInternal(View.java:6631)
at android.view.View.requestFocusNoSearch(View.java:10890)
at android.view.View.requestFocus(View.java:10869)
at android.view.View.requestFocus(View.java:10836)
at android.view.View.requestFocus(View.java:10778)
at com.example.zachmarcelo.softcash.RegisterActivity.registerUser(RegisterActivity.java:74)
at com.example.zachmarcelo.softcash.RegisterActivity.onClick(RegisterActivity.java:143)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
and this is what is supposed to be happening: (works perfectly in name text but not in other edittexts)
screenshot of mobile app
any help will be appreciated :D
My guess is that it has something to do with what you put into #style/TextLabel.
When you have an error with password or email you request focus programmatically. Which is fine, however when that happens something in your style is looking for a color resource which doesn't exist. That's what's causing the error.
The error seems to be for getColor() method of textview, your primary color has some problem, please check that.
I'm trying to find out how to set a string that will be read out-loud.
For example:
String text = "Hello";
You can find a very detail example that show how to convert text to speech on this site. HTH.
Your MainActivity.java should look something like this
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
public class MainActivity extends Activity {
TextToSpeech t1;
EditText ed1;
Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String toSpeak = ed1.getText().toString();
Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
});
}
public void onPause(){
if(t1 !=null){
t1.stop();
t1.shutdown();
}
super.onPause();
}
}
And here is the content of activity_main.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: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:transitionGroup="true">
<TextView android:text="Text to Speech" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="#+id/textView"
android:layout_below="#+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/abc"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:theme="#style/Base.TextAppearance.AppCompat" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_below="#+id/imageView"
android:layout_marginTop="46dp"
android:hint="Enter Text"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text to Speech"
android:id="#+id/button"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
</RelativeLayout>