Cannot Resolve symbol 'binding' error - java

So I recently started using binding and I enabled it in my gradle but when I try and use it I get an error? I synced the gradle and the project and everything is fine but when I try use the binding it gives me the "Cannot resolve symbol 'binding'" error. Help please! This is my 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.mike.myapplication.adminScreen"
tools:showIn="#layout/activity_admin_screen">
<EditText
android:id="#+id/nameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="37dp"
android:layout_marginTop="31dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/timeToPrepEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Time To Prepare"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/nameEditText"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="#+id/nameEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/nameEditText" />
<EditText
android:id="#+id/descEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Description"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/timeToPrepEditText"
android:layout_marginTop="7dp"
app:layout_constraintTop_toBottomOf="#+id/timeToPrepEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/timeToPrepEditText" />
<EditText
android:id="#+id/priceEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Price"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/descEditText"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="#+id/descEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/descEditText" />
<Button
android:id="#+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Item"
android:onClick="addButtonClicked"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/priceEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/priceEditText" />
<Button
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete Item"
android:onClick="deleteButtonClicked"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="#+id/addButton"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/addButton" />
<Button
android:id="#+id/databaseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Database"
android:onClick="dispDatabaseButton"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="-79dp"
app:layout_constraintTop_toBottomOf="#+id/addButton"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/addButton"
android:layout_marginLeft="156dp" />
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-41dp"
android:layout_marginStart="15dp"
android:layout_marginTop="54dp"
android:onClick="dispDatabaseButton"
android:text="Results"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="#+id/deleteButton"
app:layout_constraintTop_toBottomOf="#+id/deleteButton"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
How do I fix my error?
In addition here is the code for the activity, in my case it isn't the default main activity but instead AdminScreen.
public class adminScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_screen);
}
private void saveToDB() {
SQLiteDatabase database = new DBSQLiteHelper(this).getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Menu.MenuItems.COLUMN_NAME, binding.nameEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_PREP, binding.timeToPrepEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_DESCRIPTION, binding.descEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_PRICE, binding.priceEditText.getText().toString());
long newRowId = database.insert(Menu.MenuItems.TABLE_NAME, null, values);
Toast.makeText(this, "The new Row Id is " + newRowId, Toast.LENGTH_LONG).show();
}
}

If you mean DataBinding library you should build you layout this way
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{user.firstName}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{user.lastName}"/>
</LinearLayout>
</layout>

Related

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

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"

For a view with rotation perform(click()) doesn't work in espresso ui test

I write an espresso UI test for my application, and for some views (in this case ImageButton) perform(click()) doesn't work and also no error is displayed.
this is the line that not worked:
try {
Thread.sleep(TIME_NORMAL_ELPASED);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(allOf(withId(R.id.toolbar_navigation_btn)
, isCompletelyDisplayed())).perform(click());
and this is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="activities.DepartFlight.fragments.AvailableFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/available_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="#drawable/background_toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/toolbar_navigation_btn"
android:layout_width="#dimen/icon_toolbar"
android:layout_height="#dimen/icon_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:rotation="180"
android:src="#drawable/ic_back"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/text_toolbar_flight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:textColor="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/text_toolbar_flight"
android:layout_centerHorizontal="true"
android:textColor="#color/white"
android:textSize="#dimen/font_size" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
android:id="#+id/zero_filtered_items"
android:visibility="gone"
layout="#layout/zero_filterd_itesm_row" />
<com.faranegar.bookflight.customView.CustomRecyclerView
android:id="#+id/available_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/depart_flight_activity_footer"
android:layout_below="#id/available_toolbar"
android:background="#android:color/transparent"
android:visibility="gone"
/>
<com.tuyenmonkey.mkloader.MKLoader
android:id="#+id/progressBar"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_centerInParent="true"
android:visibility="gone"
app:mk_color="#color/colorPrimary"
app:mk_type="TwinFishesSpinner" />
<RelativeLayout
android:id="#+id/depart_flight_activity_footer"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:visibility="visible">
<LinearLayout
android:id="#+id/view_sort"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/sort_icon"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/sortText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/sort_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/view_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#id/view_sort"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_filter"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/filterText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/filter_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<RelativeLayout
android:id="#+id/next_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/back_day">
<Button
android:id="#+id/next_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/next_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/next_day_available_btn"
android:text="#string/next_day"
android:textColor="#color/white"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/back_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp">
<Button
android:id="#+id/prev_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/prev_day_available_text"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/prev_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/back_day"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/not_available_flights"
android:textColor="#android:color/black"
android:textSize="16sp"
android:visibility="gone" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/ads_motto_captan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/progressBar"
android:layout_centerInParent="true"
android:padding="15dp"
android:text="#string/captan_ads_motto"
android:textColor="#color/colorPrimary"
android:textSize="16sp"
android:visibility="gone" />
<WebView
android:id="#+id/arzanBelitBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/depart_flight_activity_footer"
android:visibility="gone" />
<include
android:id="#+id/failedLayout"
layout="#layout/failed_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<include
android:id="#+id/saatraapProgressBarLayout"
layout="#layout/saatraap_brogressbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="gone" />
and a fragment shows the above XML.
what's wrong?
I think setRotation may have confused click() and coordinates calculation. If that's the case, you could either remove android:rotation then rotate the image physically, or try to create a custom click action:
public static ViewAction forceClick() {
return new ViewAction() {
#Override public Matcher<View> getConstraints() {
return allOf(isClickable(), isEnabled());
}
#Override public String getDescription() {
return "force click";
}
#Override public void perform(UiController uiController, View view) {
view.performClick();
uiController.loopMainThreadUntilIdle();
}
};
}
This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app:
onView(withId(R.id.toolbar_navigation_btn)).perform(forceClick());
If there's no error then it's safe to assume that the click was successful. Try enabling the "Show taps" Developer option to see exactly where the click occurs.

getText() returns empty string (android studio)

I have a little question here about android development.
I already searched on internet, but i still can't find the solution.
I want to getText() from a view, but it just returns an empty ("") string.
Here's my .java code:
public void kotakCentang(View view)
{
RelativeLayout vwParentRow = (RelativeLayout)view.getParent();
TextView id_test = (TextView)vwParentRow.getChildAt(0);
TextView nama_test = (TextView)vwParentRow.getChildAt(1);
tugas_status = (TextView)vwParentRow.getChildAt(5);
tanggalKasih = (EditText)vwParentRow.getChildAt(6);
tanggalKumpul = (EditText)vwParentRow.getChildAt(8);
waktuKasih = (EditText)vwParentRow.getChildAt(7);
waktuKumpul = (EditText)vwParentRow.getChildAt(9);
tugasKompleksitas = (EditText)vwParentRow.getChildAt(10);
Tugas tugas = new Tugas();
TugasRepo tugass = new TugasRepo(this);
tugas.nama = nama_test.getText().toString();
tugas.waktuDikasih = waktuKasih.getText().toString();
tugas.waktuDikumpul = waktuKumpul.getText().toString();
tugas.tanggalDikasih = tanggalKasih.getText().toString();
tugas.tanggalDikumpul = tanggalKumpul.getText().toString();
tugas.kompleksitas=Integer.parseInt(tugasKompleksitas.getText().toString());
tugasKompleksitas.getText().toString();
}
The getText() which returns empty string is just the tugas.waktuDikasih, and tugas.waktuDikumpul .
Thank you for your help.
----- UPDATE XML ----
here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tugas_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/judul_tugas"
android:visibility="gone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="judul tugas"
android:id="#+id/tugas_judul"
android:textSize="20dp"
android:layout_marginStart="60dp"
android:layout_marginTop="17dp"
android:layout_below="#+id/tugas_id"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/status_kerja"
android:checked="false"
android:textSize="10dp"
android:layout_alignTop="#+id/tugas_judul"
android:layout_toStartOf="#+id/button"
android:onClick="kotakCentang"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimaryDark"
android:layout_below="#+id/status_kerja"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/textView2">
</View>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detil"
android:id="#+id/button"
android:layout_alignParentEnd="true"
android:textSize="10sp"
android:layout_marginEnd="16dp"
android:layout_alignTop="#+id/status_kerja"
android:layout_above="#+id/textView2"
android:onClick="detilTugas"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/status_tugas"
android:layout_alignBottom="#+id/tugas_judul"
android:layout_toEndOf="#+id/tugas_id" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_diberikan"
android:text="Tanggal Diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_diberikan"
android:layout_below="#+id/tanggal_diberikan"
android:layout_alignStart="#+id/tanggal_diberikan"
android:layout_alignEnd="#+id/tanggal_diberikan"
android:text="Waktu diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_kumpul"
android:text="Tanggal dikumpulkan"
android:layout_below="#+id/tugas_judul"
android:layout_alignStart="#+id/waktu_diberikan"
android:layout_alignEnd="#+id/waktu_diberikan"
android:textColor="#000000"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_dikumpulkan"
android:layout_below="#+id/tanggal_kumpul"
android:layout_alignStart="#+id/tanggal_kumpul"
android:layout_alignEnd="#+id/tanggal_kumpul"
android:text="Waktu dikumpulkan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/isi_kompleksitas"
android:text="Kompleksitas"
android:textColor="#000000"
android:editable="false"
android:visibility="gone"/>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="id_tugas"-->
<!--android:id="#+id/tugas_id"-->
<!--android:layout_alignBottom="#+id/status_kerja"-->
<!--android:layout_alignEnd="#+id/tugas_judul"-->
<!--android:layout_marginEnd="117dp" />-->
</RelativeLayout>

How to set list view height programatically in android

I am making an application in which my keyboard comes up on the activity and it hides may header view (layout) I have searched and tried adjust pane state hidden,adjust nothing all the attributes in manifest but nothing solved my problem then I found one the posts over stackover flow that you can calculate the spacing then set the height I implemented but the behaviour is still same this is the sanpshot when activity comes
but when keyborad pops up it hides my header view this is snapshot of what's happening
this is my manifest code
<activity
android:name="com.dd.sproutchat.ChatActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
this is my layout of that activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<RelativeLayout
android:id="#+id/TopLayout"
android:layout_width="match_parent"
android:layout_height="55dp">
<ImageButton
android:id="#+id/btn_back"
android:layout_width="20dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/back_icon_2x"
android:textColor="#000000"
android:textSize="22sp" />
<LinearLayout
android:id="#+id/Image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/btn_back">
<Button
android:id="#+id/recUserImg"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/image_circle_shape"
android:text=""
android:textColor="#color/white"
android:visibility="gone" />
<com.dd.sproutchat.customcontrols.MLRoundedImageView
android:id="#+id/userImg"
android:layout_width="50dp"
android:layout_height="50dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btn_Search"
android:layout_toRightOf="#+id/Image"
android:orientation="vertical">
<TextView
android:id="#+id/txtUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:gravity="left"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/txtOnlineStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
</LinearLayout>
<ImageButton
android:id="#+id/btn_Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/menu_icon_2x"
android:visibility="gone" />
<ImageButton
android:id="#+id/btn_Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/search_icon_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/TopLayout"
android:background="#color/chat_border"></RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_Options"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="#+id/Rl_line"
android:background="#color/chat_options_bg">
<ImageButton
android:id="#+id/btn_Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:background="#drawable/home_btn_active_2x" />
<ImageButton
android:id="#+id/btn_SproutesList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/chat_btn_2x" />
<ImageButton
android:id="#+id/btn_Note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:background="#drawable/note_btn_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_line2"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/Rl_Options"
android:background="#color/chat_border"></RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_ChatLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/Rl_MessageLayout"
android:layout_below="#+id/Rl_line2">
<!-- android:background="#drawable/chat_bg_2x" -->
<RelativeLayout
android:id="#+id/Btn_Chats"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:id="#+id/count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageButton
android:id="#+id/btn_Sortby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:background="#drawable/icon_sortby_sprout_2x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/btn_AddSprout"
android:layout_toRightOf="#+id/btn_Sortby"
android:weightSum="2">
<Button
android:id="#+id/btn_AllSprouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_blue"
android:paddingBottom="3dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="3dp"
android:text="#string/AllSprouts"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_AllFavorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:background="#drawable/btn_blank"
android:paddingBottom="3dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="3dp"
android:text="#string/AllFavorites"
android:textColor="#color/grey_start" />
</LinearLayout>
<ImageButton
android:id="#+id/btn_AddSprout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#drawable/icon_add_sprout_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/noteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="gone">
<EditText
android:id="#+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/imageButton4" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toLeftOf="#+id/imageButton5"
android:background="#drawable/sort" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#drawable/add" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/Lv_Chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/Btn_Chats"
android:layout_above="#+id/Rl_MessageLayout"
android:divider="#null"
android:dividerHeight="0dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:scrollbars="none"
android:stackFromBottom="true"
android:transcriptMode="normal"></ListView>
<RelativeLayout
android:id="#+id/Rl_MessageLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/chat_screen_bottom">
<ImageButton
android:id="#+id/btn_Attachment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/attachment_icon_white_2x" />
<EditText
android:id="#+id/edt_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btn_Send"
android:layout_toRightOf="#+id/btn_Attachment"
android:background="#drawable/txt_field"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
/>
<ImageButton
android:id="#+id/btn_Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/icon_send_white_2x" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
and this is my activity code for calculating height of listview
private static boolean keyboardHidden = true;
private static int reduceHeight =0;
final View decorView = this.getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
int displayHeight = rect.bottom - rect.top;
int height = decorView.getHeight();
boolean keyboardHiddenTemp = (double) displayHeight / height > 0.8;
int mylistviewHeight = Lv_Chat.getMeasuredHeight();
if (keyboardHiddenTemp != keyboardHidden) {
keyboardHidden = keyboardHiddenTemp;
if (!keyboardHidden) {
reduceHeight = height - displayHeight;
RelativeLayout.LayoutParams mParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mylistviewHeight - reduceHeight);
Lv_Chat.setLayoutParams(mParam);
Lv_Chat.requestLayout();
} else {
RelativeLayout.LayoutParams mParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mylistviewHeight + reduceHeight);
Lv_Chat.setLayoutParams(mParam);
Lv_Chat.requestLayout();
}
}
}
});
I have also tried this link for setting xml file
http://codetheory.in/android-add-views-view-groups-listview-gridview/
any help please
To change the height of ListView you should use LayoutParams:
ViewGroup.LayoutParams param = listView.getLayoutParams();
param.height = anynumberhere;
listView.setLayoutParams(param);
listView.requestLayout();
According to your question, this is the way to change the ListView's height, but i don't think its the rite approach to make that header of yours stay in its place.
I think you should use adjustResize instead of adjustNothing and add android:fitsSystemWindows="true" in your root RelativeLayout instead of programmatically trying to resize your views.

Categories