Not able to click the logout and posy buttons - java

I have tried checking if any layout is overlapping or not. I have tried adding more space between the button and the border nothing seems to work. I'm not able to see where am I missing out
This is the activity where I'm trying to add setonclicklistenr:
public class addPost extends AppCompatActivity {
ImageView picgal,postt;
EditText descrip,compName;
Button pst,logout;
FirebaseAuth auth;
FirebaseStorage storage;
FirebaseDatabase database;
Uri uri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_post);
picgal = findViewById(R.id.addpic);
descrip = findViewById(R.id.postDescription);
logout = findViewById(R.id.lgout);
compName = findViewById(R.id.comm);
auth = FirebaseAuth.getInstance();
storage = FirebaseStorage.getInstance();
logout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
auth.signOut();
startActivity(new Intent(addPost.this,postActivity.class));
}
});
This is the xml file:
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/lgout"
android:layout_width="75dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:background="#drawable/post_button_blue"
android:enabled="false"
android:text="LOGOUT"
android:textColor="#000000"
app:layout_constraintBottom_toBottomOf="#+id/postButton"
app:layout_constraintEnd_toStartOf="#+id/postButton"
app:layout_constraintTop_toTopOf="#+id/postButton"
tools:ignore="TouchTargetSizeCheck" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:fontFamily="#font/roboto_black"
android:text="Create Post"
android:textColor="#color/black"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="#+id/postButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/postButton" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/postButton"
android:layout_width="75dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/post_button_white"
android:enabled="false"
android:text="post"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TouchTargetSizeCheck" />
<View
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="#CFC9C9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/postButton" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="User1"
android:textColor="#color/black"
android:textSize="#dimen/_14font_mdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view" />
<EditText
android:id="#+id/comm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#android:color/transparent"
android:ems="10"
android:hint="Enter Company Name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/name" />
<EditText
android:id="#+id/postDescription"
android:layout_width="355dp"
android:layout_height="287dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:background="#android:color/transparent"
android:ems="10"
android:gravity="top"
android:hint="Type to add your experience"
android:inputType="textMultiLine"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/comm"
tools:ignore="TouchTargetSizeCheck" />
<ImageView
android:id="#+id/postpic"
android:layout_width="400dp"
android:layout_height="272dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:scaleType="centerCrop"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/view3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/postDescription"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/postDescription"
app:srcCompat="#drawable/img2"
tools:visibility="invisible" />
<ImageView
android:id="#+id/addpic"
android:layout_width="41dp"
android:layout_height="43dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/imgg" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Add to post"
android:textColor="#color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="#+id/addpic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/addpic" />
<View
android:id="#+id/view3"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="#CFC9C9"
app:layout_constraintBottom_toTopOf="#+id/addpic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshot of the .XML file design

I can See You are setting "enabled=false" in logout Button could you remove that part or replace with "enabled=true"...I will work if you do so ..please try

Related

Why get login failed while click on login button

If i click on login button my username and password is same as condition but get login failed in Toast Message. Insert correct username and password compiler going to else part. I don't know what is the problem. I am stuck from 4 hours. If you know please solve i am a newbie.
Here down is my code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView Username=(TextView) findViewById(R.id.Username);
TextView password=(TextView) findViewById(R.id.password);
Button loginbtn=(Button) findViewById(R.id.Button);
loginbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Username.getText().toString().equals("ADMIN") && password.getText().toString().equals("ADMIN")) {
Toast.makeText(getApplicationContext(), "Login Successfull", Toast.LENGTH_SHORT).show();
} else{
Toast.makeText(getApplicationContext(), "Login Faild!!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
activity.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"
android:background="#drawable/backs"
tools:context=".MainActivity">
<TextView
android:id="#+id/Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Sign in"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:background="#FFFFFF"
android:drawableLeft="#drawable/ic_baseline_person_outline_24"
android:drawablePadding="8dp"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:minHeight="48dp"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Username" />
<EditText
android:id="#+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:background="#FFFFFF"
android:drawableLeft="#drawable/ic_baseline_lock_24"
android:drawablePadding="8dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:minHeight="48dp"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edittext" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="Forgot password"
android:textColor="#000000"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.837"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/password" />
<Button
android:id="#+id/Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="28dp"
android:layout_marginRight="30dp"
android:background="#drawable/bg"
android:text="#string/login"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="288dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="or sign in with"
android:textColor="#BDB9B9"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Button" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/other"
app:layout_constraintVertical_bias="1.0">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="20dp"
android:src="#drawable/google" />
<ImageView
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="20dp"
android:src="#drawable/facebook" />
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginRight="20dp"
android:src="#drawable/twitter" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
You are referring to the R.id.Username component which is the SIGN UP text and you are casting the fields as TextViews instead of EditTexts.
Change your variables to:
EditText Username=(EditText) findViewById(R.id.edittext);
EditText password=(EditText) findViewById(R.id.password);
You are getting the text from the wrong reference, Change the below code to later.
TextView Username=(TextView) findViewById(R.id.Username);
to
TextView Username=(TextView) findViewById(R.id.edittext);

sending data of two fragments to firebase (Fragment wise or in one go)

I have two fragments in one activity. In the first fragment, I have fields like name, email, gender and phone number and by the next button replace with second fragment and on the second fragment, I have a password and confirm password fields. Now I want to send data to firebase fragment-wise or send data of two fragments at one time(by pressing the register button which is on the second fragment).but did not know how to do that
//First Fragment
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/purple_200"
tools:context=".CustomerRegisterFragment">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/personal_details"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.439"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:fontFamily="#font/courbd"
android:text="#string/user_name"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserName"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textPersonName"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/user_email"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserEmail"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textEmailAddress"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout1"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="Phone #:"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserPhone"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="phone"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:fontFamily="#font/courbd"
android:text="#string/user_gender"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="true"
android:clickable="false"
android:focusableInTouchMode="true"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_male"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_female"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_other"
android:textColor="#color/black" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="71dp"
android:layout_marginBottom="120dp"
android:background="#drawable/button_style"
android:text="#string/btn_next"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3" />
</androidx.constraintlayout.widget.ConstraintLayout>
//Second Fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:background="#color/purple_200"
tools:context=".CustomerRegisterFragment1">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerPassTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/c_password"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/CustomerRegisterFragment1.linearLayout"
android:layout_centerVertical="true"
android:layout_marginBottom="288dp"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewCustomerPassTitle"
tools:ignore="MissingConstraints">
<EditText
android:id="#+id/editTextCustomerPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/customer_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
<EditText
android:id="#+id/editTextCustomerConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/cconfirm_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="67dp"
android:layout_marginBottom="123dp"
android:background="#drawable/button_style"
android:text="#string/btn_register_client"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/CustomerRegisterFragment1.linearLayout"
app:layout_constraintVertical_bias="0.229" />
</androidx.constraintlayout.widget.ConstraintLayout>
Interface;
interface:
public interface FragmentInterface {
String getName();
String getEmail();
String getPassword();
}
Fragment:
public class FragmentA extend Fragment implements FragmentInterface{}
public class FragmentB extend Fragment implements FragmentInterface{}
xxxActivity:
FragmentInterface fia = (FragmentInterface)FragmentA;
FragmentInterface fib = (FragmentInterface)FragmentB;
get Field:
String name = fia.getName();
String pw = fib.getPassword();
BroadcastReceiver
Global singleton
you have to use bundle in fragment to pass data from one fragment to another
Without Arch. Component...
send data to another fragment
Fragment fragment = new ProductdetailFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_main,fragment);
transaction.addToBackStack(null);
transaction.commit();
Bundle bundle = new Bundle();
bundle.putString("product_id","value");
bundle.putString("product_name","value");
bundle.putString("price","value");
bundle.putString("product_desc","value");
bundle.putString("product_image",productmodels.get(position).getProduct_image());
fragment.setArguments(bundle);
get data from the previous fragment. for getting data, you have to use key of apply of the previous fragment.do not mismatch key argument
Bundle bundle = getArguments();
String product_id = bundle.getString("product_id");
String name = bundle.getString("product_name");
String price = bundle.getString("price");
String description = bundle.getString("product_desc");
String imageurl = bundle.getString("product_image");
Second Way if You use Navigation Arch. Component
Bundle bundle = new Bundle();
bundle.putString("amount", amount);
Navigation.findNavController(view).navigate(R.id.confirmationAction, bundle);

EditText getText not working in Button Click

I have two EditText in MyActivity. Here I have provided UI XML.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button_insta"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/editUrli"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView2"
android:layout_width="177dp"
android:layout_height="39dp"
android:layout_marginEnd="81dp"
android:layout_marginRight="81dp"
android:text="Paste Instagram video link to download "
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView3"
app:layout_constraintTop_toTopOf="#+id/imageView3" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="78dp"
android:layout_height="43dp"
android:layout_marginStart="41dp"
android:layout_marginLeft="41dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:src="#drawable/insta"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/card"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="8dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editUrl"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_download"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/fblogo"
android:layout_width="95dp"
android:layout_height="39dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="13dp"
android:contentDescription="TODO"
android:src="#drawable/fb"
app:layout_constraintBottom_toTopOf="#+id/editUrl"
app:layout_constraintEnd_toStartOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:layout_marginBottom="84dp"
android:text="Paste FB video link to download"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fblogo"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
In my Activity java code has this button click code
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
inputURl = findViewById(R.id.editUrl);
editUrlinsta = findViewById(R.id.editUrli);
BtnDownload = (Button) findViewById(R.id.button_download);
downloadinsta = (Button) findViewById(R.id.button_insta);
BtnDownload.setOnClickListener(this);
downloadinsta.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button_download:
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
break;
case R.id.button_insta:
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
break;
default:
break;
}
}
The problem is The first button which I have named button_download is working as expected. But the second button button_insta not working as expected. what I want to do, is When one of the buttons clicks, getting data from EditText. The button_download works fine. the button_insta is not working fine.
I couldn't get value from editUrli when the button click. But same code works for button_download and editUrl
Try to separate those button click function like so :
BtnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
}
});
downloadinsta.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
}
});

Why is my Text Change Listener not working?

Why is my "addTextChangedListener" on android not working? Here is my code:
activity_ticketing.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=".TicketingMain.Ticketing">
<!-- Main Content -->
<!-- HEADING -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:layout_marginStart="28dp"
android:layout_marginBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/icon_exit" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:minHeight="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView_route"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:text="Tacloban - Tanawan"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.285" />
<TextView
android:id="#+id/textView_vehicle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="ZZZ999"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/textView_route"
app:layout_constraintStart_toStartOf="#+id/textView_route"
app:layout_constraintTop_toBottomOf="#+id/textView_route" />
<TextView
android:id="#+id/textView_driver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Driver Name"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView_route"
app:layout_constraintTop_toTopOf="#+id/textView_route" />
<TextView
android:id="#+id/textView_conductor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:text="Conductor Name"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView_vehicle"
app:layout_constraintTop_toBottomOf="#+id/textView_driver" />
<TextView
android:id="#+id/textView_numberOfPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="0"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textView3"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="Passengers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- HEADING END -->
<!-- ROUTEPOST ORIGIN -->
<!-- ROUTEPOST ORIGIN END -->
<!-- MAIN -->
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/materialCardView">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- spinner_direction -->
<Spinner
android:id="#+id/spinner_direction"
android:layout_width="200dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="#+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<!-- textView_currentPost -->
<TextView
android:id="#+id/textView_currentPost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#drawable/border_box"
android:text="Current"
android:textAlignment="center"
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/button_prev"
app:layout_constraintEnd_toStartOf="#+id/button_next"
app:layout_constraintStart_toEndOf="#+id/button_prev"
app:layout_constraintTop_toTopOf="#+id/button_prev" />
<!-- button_next -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:textAlignment="center"
app:icon="#drawable/ic_right_arrow"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView_currentPost"
app:layout_constraintTop_toBottomOf="#+id/spinner_direction" />
<!-- button_prev -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textStyle="bold"
app:icon="#drawable/ic_left"
app:iconGravity="textStart"
app:layout_constraintEnd_toStartOf="#+id/textView_currentPost"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/spinner_direction" />
<!-- button_postCurrentRoutePost -->
<!-- button_logout -->
<!-- textView = "Direction" -->
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Direction"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- textView_currentLocation -->
<TextView
android:id="#+id/textView_currentLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="No current location set"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="#+id/button_next"
app:layout_constraintStart_toStartOf="#+id/button_prev"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPost" />
<!-- button_nextDestination -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_nextDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAlignment="center"
app:icon="#drawable/ic_right_arrow"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="#+id/textView_currentLocation"
app:layout_constraintStart_toEndOf="#+id/textView_currentPost"
app:layout_constraintTop_toBottomOf="#+id/textView_currentLocation" />
<!-- button_prevDestination -->
<com.google.android.material.button.MaterialButton
android:id="#+id/button_prevDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:textAlignment="center"
android:textStyle="bold"
app:icon="#drawable/ic_left"
app:iconGravity="textStart"
app:layout_constraintEnd_toStartOf="#+id/textView_currentPost"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_currentLocation" />
<!-- textView_currentPostDestination -->
<TextView
android:id="#+id/textView_currentPostDestination"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#drawable/border_box"
android:text="Current"
android:textAlignment="center"
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"
android:clickable="true"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="#+id/button_prevDestination"
app:layout_constraintEnd_toStartOf="#+id/button_nextDestination"
app:layout_constraintStart_toEndOf="#+id/button_prevDestination"
app:layout_constraintTop_toTopOf="#+id/button_nextDestination" />
<com.google.android.material.button.MaterialButton
android:id="#+id/button_postDestination"
style="#style/Widget.MaterialComponents.Button"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_marginTop="8dp"
android:text="Submit Destination"
android:textAlignment="center"
app:iconGravity="textStart"
app:layout_constraintEnd_toEndOf="#+id/button_nextDestination"
app:layout_constraintStart_toStartOf="#+id/textView_currentPostDestination"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPostDestination" />
<!-- RECEIPT -->
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView3"
android:layout_width="347dp"
android:layout_height="332dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button_postDestination">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="Destination"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView_receiptDestination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Tacloban - Tanawan"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView4"
app:layout_constraintTop_toTopOf="#+id/textView4" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Passengers"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView4"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView_receiptPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="0"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/textView6"
app:layout_constraintTop_toTopOf="#+id/textView6" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Fare"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView6"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<TextView
android:id="#+id/textView_receiptFare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/textView_receiptPassengers"
app:layout_constraintTop_toTopOf="#+id/textView8" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Total Due"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="#+id/textView8"
app:layout_constraintTop_toBottomOf="#+id/textView8" />
<TextView
android:id="#+id/textView_receiptTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/textView_receiptFare"
app:layout_constraintTop_toTopOf="#+id/textView10" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView4"
android:layout_width="108dp"
android:layout_height="97dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="#+id/textView_receiptTotal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView_receiptDestination">
<ImageView
android:id="#+id/imageView_qrCode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
</com.google.android.material.card.MaterialCardView>
<RadioGroup
android:id="#+id/radioGroup_discount"
android:layout_width="205dp"
android:layout_height="106dp"
android:layout_marginEnd="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10"
app:layout_constraintVertical_bias="0.615">
<RadioButton
android:id="#+id/radioButton_noDiscount"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:checked="true"
android:text="No Discount"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<RadioButton
android:id="#+id/radioButton_ssDiscount"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:text="Senior/Student"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<RadioButton
android:id="#+id/radioButton_spDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:text="Special Discount"
android:textSize="12sp"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="#+id/button_accept"
android:layout_width="108dp"
android:layout_height="74dp"
android:text="Accept"
app:backgroundTint="#009688"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/materialCardView4"
app:layout_constraintStart_toStartOf="#+id/materialCardView4"
app:layout_constraintTop_toBottomOf="#+id/materialCardView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- <SearchView-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="0dp"-->
<!-- android:id="#+id/search"-->
<!-- app:layout_constraintBottom_toBottomOf="#+id/button_postDestination"-->
<!-- app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"-->
<!-- app:layout_constraintStart_toStartOf="#+id/button_prevDestination"-->
<!-- app:layout_constraintTop_toTopOf="#+id/button_postDestination" />-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="#+id/editText"
app:layout_constraintBottom_toBottomOf="#+id/button_postDestination"
app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"
app:layout_constraintStart_toStartOf="#+id/button_prevDestination"
app:layout_constraintTop_toBottomOf="#+id/button_prevDestination">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textKm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Km" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!-- MAIN END -->
<!-- MAIN -->
<!-- HEADING -->
<!-- LOGOUT -->
<!-- LOGOUT END -->
</androidx.constraintlayout.widget.ConstraintLayout>
Ticketing.java
EditText editText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ticketing);
editText = (EditText) findViewById(R.id.textKm);
editText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.e("TEXT", "A");
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e("TEXT", "A");
}
#Override
public void afterTextChanged(Editable s) {
Log.e("TEXT", "A");
}
});
}
I don't get any error. On debugging, it doesn't stop on any of the overrides.
You can set in tow way
First Way:
EditText et_auto_complete_edit_text;
et_auto_complete_edit_text = findViewById(R.id.et_auto_complete_edit_text);
et_auto_complete_edit_text.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
s.toString()
}
});
XML:
<EditText
android:id="#+id/et_auto_complete_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="8"
android:background="#color/gray_light_EA"
android:drawableRight="#mipmap/ic_search_new"
android:drawablePadding="#dimen/margin5dp"
android:hint="Search here"
android:inputType="text"
android:maxLines="1"
android:padding="10dp"
android:textColor="#color/black"
android:textColorHint="#color/grey"
android:visibility="visible" />
Second Way :
SearchView search;
search = findViewById(R.id.search);
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
fetchData(query);
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
//collectionProductsListAdapter.getFilter().filter(newText);
return false;
}
});
search.setOnSearchClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
search.setOnCloseListener(new SearchView.OnCloseListener() {
#Override
public boolean onClose() {
return false;
}
});
XML:
<androidx.appcompat.widget.SearchView
xmlns:n2="http://schemas.android.com/tools"
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
n2:searchIcon="#mipmap/ic_et_search" />
Hope this may help you first way is more easy.
Try changing it to EditText
<android.support.design.widget.TextInputLayout
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Km"
app:layout_constraintEnd_toEndOf="#+id/button_prevDestination"
app:layout_constraintStart_toStartOf="#+id/button_prevDestination"
app:layout_constraintTop_toBottomOf="#+id/textView_currentPostDestination">
<EditText
android:id="#+id/textKm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
Working fine in my code.

Android actionbar/toolbar disappears after writing to edittext [duplicate]

This question already has answers here:
Android Toolbar moves up when keyboard appears
(17 answers)
Closed 4 years ago.
I'm stuck at this. I have an app where I have several pages made as fragments. Every page is good except the last one where when I tap on editText, action bar disappears and when I unfocus it, action bar didn't show up back.
I've tried changing appTheme to all kind of themes but they didn't change anything, most of them forced app to crash.
Here is my layout of that page
<?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=".MainActivity$PlaceholderFragment">
<ImageView
android:id="#+id/imageView27"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="#+id/imageView28"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13" />
<ImageView
android:id="#+id/imageView29"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.64"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<ImageView
android:id="#+id/imageView30"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/imageView31"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<ImageView
android:id="#+id/imageView32"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65" />
<ImageView
android:id="#+id/imageView33"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.78" />
<ImageView
android:id="#+id/imageView34"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.91" />
<TextView
android:id="#+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/houroff"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView27"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.03" />
<TextView
android:id="#+id/minuteOffsetText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minuteoff"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView28"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.16" />
<TextView
android:id="#+id/vinText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vinen"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView29"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.29" />
<TextView
android:id="#+id/defaultText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/defen"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView30"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.40" />
<TextView
android:id="#+id/vhconst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/vehicle_const"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView31"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<TextView
android:id="#+id/shft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/output"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView32"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.645" />
<TextView
android:id="#+id/tripText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TRIP\nRESET"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView33"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.76" />
<TextView
android:id="#+id/odoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/odores"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/imageView34"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.895" />
<Switch
android:id="#+id/minOffSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.155" />
<Switch
android:id="#+id/vinSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.285" />
<Switch
android:id="#+id/defaultSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.40" />
<Switch
android:id="#+id/tripResetSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.76" />
<Switch
android:id="#+id/odoResetSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.895" />
<EditText
android:id="#+id/eVehConstSet"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/frame"
android:ems="10"
android:hint="00000"
android:inputType="number"
android:singleLine="true"
android:textAlignment="textEnd"
android:textColor="#android:color/background_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toEndOf="#+id/vhconst"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.52" />
<EditText
android:id="#+id/eOutShaftSet"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/frame"
android:ems="10"
android:hint="0.000"
android:inputType="number|numberSigned|numberDecimal"
android:singleLine="true"
android:textAlignment="textEnd"
android:textColor="#android:color/background_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.1"
app:layout_constraintStart_toEndOf="#+id/shft"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.645" />
<TextView
android:id="#+id/hourOffset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="0"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintStart_toEndOf="#+id/textView25"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.02" />
<TextView
android:id="#+id/minOffset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="0"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.7"
app:layout_constraintStart_toEndOf="#+id/textView25"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13999999" />
<TextView
android:id="#+id/vinResetText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VIN RESET"
android:textAlignment="center"
android:textColor="#android:color/black"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/vinReset"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.29" />
<ImageView
android:id="#+id/vinReset"
android:layout_width="60dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<Switch
android:id="#+id/vinResS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.11"
app:layout_constraintStart_toEndOf="#+id/vinResetText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.27999997" />
<TextView
android:id="#+id/pulsem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/fraction"
android:text="#string/vehicle_const_pm"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/eVehConstSet"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.51" />
<TextView
android:id="#+id/pulser"
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:background="#drawable/fraction"
android:text="#string/output_const"
android:textAlignment="center"
android:textColor="#android:color/background_dark"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/eOutShaftSet"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64" />
and this is my MainActivity
public class MainActivity extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
public static float density = 0;
public static float dpHeight = 0;
public static float dpWidth = 0;
public String macAdress;
public UUID myUUID;
public static int index = 1;
public boolean ConnectSuccess = false;
private ProgressDialog progress;
public BluetoothSocket btSocket = null;
public BluetoothAdapter mBluetooth = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
}
#Override
public void onPageSelected(int position) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
TextView t = findViewById(R.id.title);
switch (position+1){
case 1:
t.setText("Virtual TG Setup");
break;
case 2:
t.setText("Virtual TG Live");
break;
case 3:
t.setText("Virtual TG Config");
break;
}
}
#Override
public void onPageScrollStateChanged(int state) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().show();
}
});
Display d = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics();
d.getMetrics(outMetrics);
density = getResources().getDisplayMetrics().density;
dpHeight = outMetrics.heightPixels / density;
dpWidth = outMetrics.widthPixels / density;
System.out.println(density);
System.out.println(dpHeight);
System.out.println(dpWidth);
System.out.println(outMetrics.heightPixels);
System.out.println(outMetrics.widthPixels);
Intent intent = getIntent();
macAdress = intent.getStringExtra("EXTRA");
if (macAdress != null) {
new BTConnect().execute();
} else {
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
You can try to set windowSoftInputMode in manifest. Choose which is most suitable for you.
<activity android:name="com.example.app.MainActivity"
android:windowSoftInputMode="adjustResize">

Categories