Reputation: 139
Hello I have a problem with setting the visibility of the cardView
part.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout(..........)>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
(..........)>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/titleLayout"
(..........)>
<TextView
android:id="@+id/text_view_title"
(..........)/>
<androidx.constraintlayout.widget.ConstraintLayout
android:visibility="gone" <<<<<<<<<
android:id="@+id/expandableView"
(..........)>
<TextView
android:id="@+id/text_view_description"
(..........) />
<TextView
android:id="@+id/text_view_priority"
(..........) />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
How you can see I divided the cardView
into two parts. In my showDescription()
method I want to change the visibility of description section to visible or (if it's already visible) to gone.
View cardView = inflater.inflate(R.layout.note_item, container, false);
final ConstraintLayout expandableView = cardView.findViewById(R.id.expandableView);
adapter.setOnItemClickListener(new NoteAdapter.OnItemClickListener() {
@Override
public void onItemClick(final DocumentSnapshot documentSnapshot, int position) {
Note note = documentSnapshot.toObject(Note.class);
int pathInt = position;
String path =String.valueOf(pathInt);
showDescription(expandableView);
}
});
return RootView;
}
public void showDescription (ConstraintLayout expandableView){
if(expandableView.getVisibility()== View.VISIBLE){
expandableView.setVisibility(View.GONE);
}else {
expandableView.setVisibility(View.GONE);
}
}
}
I don't know why but after click on cardView
(no matter which one) nothing happens. Maybe it's since my app don't know on witch cardView
execute that method ? How I can make it works ?
Upvotes: 0
Views: 381
Reputation: 1801
The problem is here:
final ConstraintLayout expandableView = cardView.findViewById(R.id.expandableView);
You are making your expandableView
final
. final
variable can not be modified. Remove the final
keyword:
ConstraintLayout expandableView = cardView.findViewById(R.id.expandableView);
I think also you should place your showDescription
function's code inside setOnItemClickListener
instead of passing `expandableView' to a function.
Upvotes: 1