Button disappears when another is clicked - java

I have an app with 6 buttons that, when clicked, display strings with different lengths:
<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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="116dp"
android:layout_marginStart="16dp"
android:layout_marginTop="128dp"
android:text=""
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#+id/atbutt"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.028" />
<Button
android:id="#+id/namebutt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="116dp"
android:layout_marginStart="16dp"
android:onClick="changename"
android:text="Name"
app:layout_constraintBaseline_toBaselineOf="#+id/titlebutt"
app:layout_constraintEnd_toStartOf="#+id/descbutt"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/titlebutt"
android:layout_width="103dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="changetitle"
android:text="Title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.448"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/descbutt"
android:layout_width="126dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:onClick="changedesc"
android:text="Description"
app:layout_constraintBaseline_toBaselineOf="#+id/titlebutt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/namebutt" />
<Button
android:id="#+id/urlbutt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="116dp"
android:layout_marginStart="16dp"
android:text="Url"
app:layout_constraintEnd_toStartOf="#+id/contbutt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/namebutt" />
<Button
android:id="#+id/atbutt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="133dp"
android:text="Publish Date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/namebutt" />
<Button
android:id="#+id/contbutt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="4dp"
android:text="Content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/urlbutt"
app:layout_constraintTop_toBottomOf="#+id/titlebutt" />
</android.support.constraint.ConstraintLayout>
When I click namebutt, titlebutt or descbutt ( the only ones that have the onClick function at the moment), atbutt just disappears with no errors.
The onClicks:
public void changename(View view){
textView.setText(null);
for(int a=0; a<articles.size(); a++) {
textView.append(articles.get(a).nam);
}
}
public void changetitle(View view){
textView.setText(null);
for(int a=0; a<articles.size(); a++) {
textView.append(articles.get(a).titl);
}
}
public void changedesc(View view){
textView.setText(null);
for(int a=0; a<articles.size(); a++) {
textView.append(articles.get(a).desc);
}
}
This only happens to atbutt
PS: I'm sorry for my choice in naming my buttons

This happens because of this attribute of atbutt:
app:layout_constraintStart_toEndOf="#+id/textView"
which means that the start of atbutt is at the end of the TextView and as the TextView grows it eliminates atbutt's size.
Change to something like this:
<Button
android:id="#+id/atbutt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="133dp"
android:text="Publish Date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/urlbutt"
app:layout_constraintTop_toBottomOf="#+id/namebutt" />

Related

Not able to click the logout and posy buttons

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

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);

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();
}
});

Fix Overlapping Collapsing/Expanding Cards Java

I am using Android Studio to create 2 CardViews that expand and collapse on a mouseclick. However, when I expand a card, the card underneath does not get pushed down and still visible even if the card above is expanded and is an overlap problem.
How do i fix this so either the card below the one being expanded gets pushed down or that the card that is being expanded information is at the front?
Screenshot of how cards look before clicked:Before Clicked
screenshot of when when clicked: when clicked (as you can see the 'Steven Smith card is still being shown)
Note: I did look into using a Recycler View + adapter etc. but in each card I would want different layouts/images (vs all being consistent info like a contact in someones phone)
Here is my java code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_engineering_page);
expandableView = findViewById(R.id.expandableView);
arrowBtn = findViewById(R.id.arrowBtn);
cardView = findViewById(R.id.cardView);
arrowBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView.getVisibility()==View.GONE){
TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
expandableView.setVisibility(View.VISIBLE);
arrowBtn.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
expandableView.setVisibility(View.GONE);
arrowBtn.setBackgroundResource(R.drawable.android_icon);
}
}
});
expandableView2 = findViewById(R.id.expandableView2);
arrowBtn2 = findViewById(R.id.arrowBtn2);
cardView2 = findViewById(R.id.cardView2);
arrowBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView2.getVisibility()==View.GONE){
TransitionManager.beginDelayedTransition(cardView2, new AutoTransition());
expandableView2.setVisibility(View.VISIBLE);
arrowBtn2.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(cardView2, new AutoTransition());
expandableView2.setVisibility(View.GONE);
arrowBtn2.setBackgroundResource(R.drawable.android_icon);
}
}
});
}
}
Here is my XML code:
<?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=".EngineeringPage"
android:background="#22325A">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:background="#C4C4C4"
app:logo="#drawable/image1"
app:title="">
</android.support.v7.widget.Toolbar>
<TextView
android:id="#+id/engineeringTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="409dp"
android:layout_marginEnd="111dp"
android:layout_marginLeft="111dp"
android:layout_marginRight="111dp"
android:layout_marginStart="111dp"
android:layout_marginTop="61dp"
android:text="Engineering"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CardView.Light"
android:layout_marginTop="98dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Section 1"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp" />
<Button
android:id="#+id/arrowBtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:visibility="gone"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="#+id/phoneIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="52dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/phoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="(999) 345 32 45"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/phoneIcon"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc"/>
<TextView
android:id="#+id/phoneDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Mobile"
android:layout_marginStart="32dp"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon"/>
<ImageView
android:id="#+id/mailIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="22dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon"/>
<TextView
android:id="#+id/mailNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="workemail#gmail.com"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/mailIcon"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toTopOf="#+id/mailDesc"/>
<TextView
android:id="#+id/mailDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Work"
android:layout_marginStart="32dp"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/mailNumber"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
style="#style/CardView.Light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="184dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
android:id="#+id/name2"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="Steven Smith" />
<Button
android:id="#+id/arrowBtn2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:paddingBottom="12dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/phoneIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="52dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/phoneNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="(999) 345 32 45"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toTopOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/phoneDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Mobile"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber2" />
<ImageView
android:id="#+id/mailIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="22dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/mailNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="workemail#gmail.com"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/mailDesc2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toTopOf="#+id/mailIcon2" />
<TextView
android:id="#+id/mailDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Work"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toBottomOf="#+id/mailNumber2" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
I have modified your sample to make it work correctly, you need to animated the parent layout for the two cardViews to make the animation smoth
java
final ConstraintLayout content = findViewById(R.id.content_layout);
final ConstraintLayout expandableView = findViewById(R.id.expandableView);
final Button arrowBtn = findViewById(R.id.arrowBtn);
arrowBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView.getVisibility() == View.GONE) {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView.setVisibility(View.VISIBLE);
arrowBtn.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView.setVisibility(View.GONE);
arrowBtn.setBackgroundResource(R.drawable.android_icon);
}
}
});
final ConstraintLayout expandableView2 = findViewById(R.id.expandableView2);
final Button arrowBtn2 = findViewById(R.id.arrowBtn2);
arrowBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (expandableView2.getVisibility() == View.GONE) {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView2.setVisibility(View.VISIBLE);
arrowBtn2.setBackgroundResource(R.drawable.down_arrow);
} else {
TransitionManager.beginDelayedTransition(content, new AutoTransition());
expandableView2.setVisibility(View.GONE);
arrowBtn2.setBackgroundResource(R.drawable.android_icon);
}
}
});
xml
<?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"
android:id="#+id/content_layout"
android:background="#22325A">
<android.support.v7.widget.Toolbar
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/toolbar"
android:background="#C4C4C4"
app:logo="#drawable/logo"
app:title="">
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/CardView.Light"
android:layout_marginTop="98dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Section 1"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp" />
<Button
android:id="#+id/arrowBtn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintTop_toTopOf="#id/name"
app:layout_constraintBottom_toBottomOf="#id/name"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="#id/arrowBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:id="#+id/phoneIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="#drawable/logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/phoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="(999) 345 32 45"
android:layout_marginStart="32dp"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/phoneIcon"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc"/>
<TextView
android:id="#+id/phoneDesc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Mobile"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber"
app:layout_constraintStart_toEndOf="#id/phoneIcon"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon"/>
<ImageView
android:id="#+id/mailIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="22dp"
android:layout_marginStart="12dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon"/>
<TextView
android:id="#+id/mailNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="workemail#gmail.com"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
android:textColor="#000"
style="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintTop_toTopOf="#+id/mailIcon"
app:layout_constraintStart_toEndOf="#id/mailIcon"
app:layout_constraintBottom_toTopOf="#+id/mailDesc"/>
<TextView
android:id="#+id/mailDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:textColor="#8A000000"
style="#style/TextAppearance.AppCompat.Body1"
app:layout_constraintStart_toStartOf="#id/phoneNumber"
app:layout_constraintTop_toBottomOf="#+id/mailNumber"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardView2"
style="#style/CardView.Light"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardView">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp">
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/name2"
style="#style/TextAppearance.AppCompat.Title"
android:layout_marginStart="12dp"
android:text="Steven Smith" />
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="12dp"
android:background="#drawable/down_arrow"
app:layout_constraintTop_toTopOf="#id/name2"
app:layout_constraintBottom_toBottomOf="#id/name2"
app:layout_constraintEnd_toEndOf="parent"
android:id="#+id/arrowBtn2"
/>
<android.support.constraint.ConstraintLayout
android:id="#+id/expandableView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
app:layout_constraintTop_toBottomOf="#id/arrowBtn2"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="#+id/phoneIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:src="#drawable/logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="#+id/phoneNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="(999) 345 32 45"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/phoneDesc2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toTopOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/phoneDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
android:text="Mobile"
android:textColor="#8A000000"
app:layout_constraintBottom_toBottomOf="#+id/phoneIcon2"
app:layout_constraintStart_toEndOf="#id/phoneIcon2"
app:layout_constraintTop_toBottomOf="#+id/phoneNumber2" />
<ImageView
android:id="#+id/mailIcon2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="12dp"
android:layout_marginTop="22dp"
android:src="#drawable/android_icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/phoneIcon2" />
<TextView
android:id="#+id/mailNumber2"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
android:text="workemail#gmail.com"
android:textColor="#000"
app:layout_constraintBottom_toTopOf="#+id/mailDesc2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toTopOf="#+id/mailIcon2" />
<TextView
android:id="#+id/mailDesc2"
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:textColor="#8A000000"
app:layout_constraintStart_toStartOf="#id/phoneNumber2"
app:layout_constraintBottom_toBottomOf="#+id/mailIcon2"
app:layout_constraintStart_toEndOf="#id/mailIcon2"
app:layout_constraintTop_toBottomOf="#+id/mailNumber2" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Just put everything inside a Linear Layout orientation vertical or Inside other layouts align your bottom and tops correctly with android:layout_below="#+id/YOUR ID"

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.

Categories