New to Android (Java) development and I have a fragment (WidgetFragment) that is backed by a binding to a widget.xml file.
WidgetFragment:
public class WidgetFragment extends Fragment {
private WidgetBinding binding;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
binding = WigetBinding.inflate(inflater, container, false);
return binding.getRoot();
}
public void onViewCreated(@NonNull View view, Bundle bundle) {
super.onViewCreated(view, bundle);
}
@Override
public void onDestroyiew() {
super.onDestroyView();
binding = null;
}
}
widget.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=".WidgetFragment">
<TextView
android:id="@+id/textview_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_second"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/previous"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_second" />
</androidx.constraintlayout.widget.ConstraintLayout>
I also have just created a List<MediaFileModel>, where MediaFileModel looks like:
public class MediaFileModel {
private Bitmap thumbnail;
private String absPath;
// ctor, getters and setters omitted for brevity
}
I would now like to "inject" that List<MediaFileModel> into my WidgetFragment (both the XML view layer as well as in the WidgetFragment java code) so that:
- I get a visual list representing the
List<MediaFileModel>; and - each list element represents an individual
MediaFileModelinstance; and - each list element (representing a different
MediaFileModeldisplays a checkbox with a label; the label is thethumbnail : Bitmapof theMediaFileModel
So essentially, by injecting this List<MediaFileModel> the end user will see a list of thumbnails, each with a checkbox next to them. How do I inject this list and get the desired "list of checkable thumbnails" effect?
from Displaying a list of checkable images inside Android fragment/view
No comments:
Post a Comment