When Bottom sheet is open(First image below) and
When tab on editText , the keyboard hides the edit text(Second image below) , i want to move keyword below the "ADD" botton of bottomsheet.How to do this?
Image 2:
Fragment
public class CustomExerciseFragment extends BaseCardFragment {
private View parent_view;
private RecyclerView recyclerView;
private AdapterEasyListAnimation mAdapter;
private LinkedList<DaysDetails> items = new LinkedList<>();
private int animation_type = ItemAnimation.BOTTOM_UP;
private DaysDAO daysDAO;
private ExercisesDAO exercisesDAO;
private ImageView imageView;
private Button buttonBreif;
//=========Configure this at the beginning=============
private final String routineId="1520";
private final String legWorkoutImageName="leg_workout_customize";
private BottomSheetBehavior mBehavior;
private BottomSheetDialog mBottomSheetDialog;
private View bottom_sheet;
public static CustomExerciseFragment newInstance() {
CustomExerciseFragment fragment = new CustomExerciseFragment();
return fragment;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_custom_exercise, container, false);
mCardView = (CardView) root.findViewById(R.id.cardView);
mCardView.setMaxCardElevation(mCardView.getCardElevation()
* CardAdapter.MAX_ELEVATION_FACTOR);
bottom_sheet = root.findViewById(R.id.bottom_sheet_add_days);
mBehavior = BottomSheetBehavior.from(bottom_sheet);
mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
((ExtendedFloatingActionButton) root.findViewById(R.id.extended_fab)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showAddDaysBottomSheetDialog();
}
});
return root;
}
private void showAddDaysBottomSheetDialog() {
if (mBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
mBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
final View view = getLayoutInflater().inflate(R.layout.sheet_add_days, null);
mBottomSheetDialog = new BottomSheetDialog(getContext());
mBottomSheetDialog.setContentView(view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBottomSheetDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
mBottomSheetDialog.show();
mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
mBottomSheetDialog = null;
}
});
}
}
BottomSheetLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:id="#+id/nested_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
android:layout_gravity="bottom"
android:scrollingCache="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/spacing_middle"
android:paddingLeft="#dimen/spacing_mlarge"
android:paddingRight="#dimen/spacing_mlarge"
android:paddingTop="#dimen/spacing_middle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_medium"
android:orientation="vertical"
android:padding="#dimen/spacing_medium">
<EditText
style="#style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="#dimen/spacing_xmlarge"
android:background="#drawable/edit_text_round_bg_outline"
android:inputType="text"
android:minHeight="#dimen/spacing_xmlarge"
android:paddingLeft="#dimen/spacing_large"
android:paddingRight="#dimen/spacing_large"
android:text="400" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_middle"
android:orientation="vertical">
<Button
style="#style/Button.Primary.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/btn_rect_black_grey"
android:text="ADD"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
Related
This question already has answers here:
CardViews not showing in RecyclerView
(3 answers)
Closed 2 years ago.
activity_driver_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".DriverListActivity">
<include
android:id="#+id/toolbarDL"
layout="#layout/toolbar"/>
<RelativeLayout
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</LinearLayout>
fragment_driver_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".DLFragment.DriverListFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/driverList"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
raw_driver_list.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="5dp"
app:cardCornerRadius="4dp"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="95dp"
android:layout_height="95dp"
android:padding="10dp"
android:src="#drawable/ic_android"
app:civ_border_width="2dp"
app:civ_border_color="#color/quantum_lightgreen"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/carName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Suzuki Abcd"
android:text="SUZUKI Wagon r"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:textColor="#color/places_text_black_alpha_87"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/driverNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="0312-1234567"
android:text="0312-1234567"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:textColor="#color/cardview_dark_background"
android:textSize="15sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
DriverListAdapter.Java
public class DriverListAdapter extends RecyclerView.Adapter<DriverListAdapter.DriverListViewHolder> {
private ArrayList<Driver> mLst;
public class DriverListViewHolder extends RecyclerView.ViewHolder{
public CircleImageView mImage;
public TextView mCName, mDNumber;
public DriverListViewHolder(#NonNull View itemView) {
super(itemView);
mImage = itemView.findViewById(R.id.profile_image);
mCName = itemView.findViewById(R.id.carName);
mDNumber = itemView.findViewById(R.id.driverNumber);
}
}
#NonNull
#Override
public DriverListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.raw_driver_list, parent, false);
DriverListViewHolder driverListAdapter = new DriverListViewHolder(view);
return driverListAdapter;
}
#Override
public void onBindViewHolder(#NonNull DriverListViewHolder holder, int position) {
Driver driver = mLst.get(position);
holder.mImage.setImageResource(driver.getdImage());
holder.mCName.setText(driver.getdCName());
}
#Override
public int getItemCount()
{
return mLst.size();
}
public DriverListAdapter(ArrayList<Driver> lst) {
this.mLst = lst;
}
}
DriverListFragment.Java
public class DriverListFragment extends Fragment {
public static final String TAG = "DriverListFragment";
private ArrayList<Driver> driverLst;
private RecyclerView mRecyclerView;
private RecyclerView.LayoutManager mLayoutManager;
private DriverListAdapter mAdapter;
public DriverListFragment() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_driver_list, container, false);
driverLst = new ArrayList<>();
driverLst.add(new Driver(R.drawable.ic_android,"Car One","0312-1234567"));
driverLst.add(new Driver(R.drawable.ic_android,"Car Two","0312-1234567"));
driverLst.add(new Driver(R.drawable.ic_android,"Car Three","0312-1234567"));
driverLst.add(new Driver(R.drawable.ic_android,"Car Four","0312-1234567"));
driverLst.add(new Driver(R.drawable.ic_android,"Car Five","0312-1234567"));
mRecyclerView = (RecyclerView) v.findViewById(R.id.driverList);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this.getActivity());
mAdapter = new DriverListAdapter(driverLst);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
return v;
}
}
DriverListActivity.Java
public class DriverListActivity extends AppCompatActivity {
public static final String TAG = "DriverListActivity";
private TDD tdd = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_driver_list);
initToolbar();
getMyIntent();
driverList();
}
private void getMyIntent()
{
Intent i = getIntent();
tdd = (TDD) i.getSerializableExtra("tdd");
Log.d(TAG,tdd.toString());
}
private void initToolbar()
{
Toolbar toolbar = findViewById(R.id.toolbarDL);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Hello There..");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public void driverList()
{
DriverListFragment driverListFragment = new DriverListFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragmentContainer,driverListFragment);
fragmentTransaction.addToBackStack("driverListFragment");
fragmentTransaction.commit();
}
}
I want to show my RecyclerView list in fragment instead of an activity, when i call fragment in activity it simply showing me blank activity however, there's no error in code. How can i achieve this task or where i am doing a mistake?
How to build a Horizontal ListView with RecyclerView?
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);
I have a RecyclerView inside BottomSheetDialogFragment. The RecyclerView items touch working normally when it's scrolling slowly.
But when the RecyclerView is scrolled fast and after the list stops (without touching), than touching on any item doesn't work on fast touch. It needs double touching.
See in the below example gif, when touching on Andhra Pradesh it's working fine. After slow scrolling, touching on Haryana also works fine. Then doing a fast scroll and touching on Punjab doesn't work on the first touch. Touching again it works.
Following is the code:
OperatorListDialogFragment.java
package com.*;
import *;
public class OperatorListDialogFragment extends BottomSheetDialogFragment{
private static final String ARG_NAME = "item_name";
private static final String ARG_LOGO = "item_logo";
private Listener mListener;
private String header;
private Context mContext;
public static OperatorListDialogFragment newInstance(String[] name, int[] logo, String header) {
final OperatorListDialogFragment fragment = new OperatorListDialogFragment();
final Bundle args = new Bundle();
args.putStringArray(ARG_NAME, name);
args.putIntArray(ARG_LOGO, logo);
args.putString("header", header);
fragment.setArguments(args);
return fragment;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog, container, false);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
TextView headerTV = view.findViewById(R.id.title);
headerTV.setText(getArguments().getString("header"));
final RecyclerView recyclerView = view.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(new OperatorAdapter(getArguments().getStringArray(ARG_NAME), getArguments().getIntArray(ARG_LOGO)));
view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
});
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
final Fragment parent = getParentFragment();
if (parent != null) {
mListener = (Listener) parent;
} else {
mListener = (Listener) context;
}
}
#Override
public void onDetach() {
mListener = null;
super.onDetach();
}
public interface Listener {
void onFilterSelected(String selected, String selectedQuery);
}
private class ViewHolder extends RecyclerView.ViewHolder {
final TextView text;
ImageView logo;
ViewHolder(LayoutInflater inflater, ViewGroup parent) {
// TODO: Customize the item layout
super(inflater.inflate(R.layout.fragment_operator_list_dialog_list_dialog_item, parent, false));
text = itemView.findViewById(R.id.tv_operator_name);
logo = itemView.findViewById(R.id.iv_recharge_provider_icon);
}
}
private class OperatorAdapter extends RecyclerView.Adapter<ViewHolder> {
private String[] mNames;
private int[] mLogos;
OperatorAdapter(String[] name, int[] logo) {
mNames = name;
mLogos = logo;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.text.setText(mNames[position]);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("clicked", "" + position);
}
});
}
#Override
public int getItemCount() {
return mNames.length;
}
}
}
dialog.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_height="match_parent"
android:layout_width="match_parent"
>
<ImageView
android:focusable="true"
android:clickable="true"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="Close"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:id="#+id/dismiss"
android:padding="14dp"
android:src="#drawable/ic_close_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/title"
app:layout_constraintTop_toTopOf="#id/dismiss"
app:layout_constraintBottom_toBottomOf="#id/dismiss"
app:layout_constraintLeft_toRightOf="#id/dismiss"
android:padding="14dp"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
tools:text="Select operator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View
app:layout_constraintTop_toBottomOf="#id/dismiss"
android:background="#969696"
android:layout_width="match_parent"
android:layout_height="0.5dp"/>
<androidx.recyclerview.widget.RecyclerView
app:layout_constraintTop_toBottomOf="#id/dismiss"
app:layout_constraintBottom_toBottomOf="parent"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_constrainedHeight="true"
android:paddingTop="#dimen/list_item_spacing_half"
android:paddingBottom="#dimen/list_item_spacing_half"
tools:context=".fragments.OperatorListDialogFragment"
tools:listitem="#layout/fragment_operator_list_dialog_list_dialog_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
recycler_item.xml
<?xml version="1.0" encoding="utf-8"?>
<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:gravity="center_vertical"
android:orientation="horizontal"
android:id="#+id/ll_operator_list_wrapper"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:visibility="gone"
android:layout_marginLeft="16dp"
android:id="#+id/iv_recharge_provider_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginVertical="16dp"
android:layout_centerVertical="true"
android:src="#drawable/ic_bsnl_logo"
tools:visibility="visible"/>
<TextView
android:padding="16dp"
android:textColor="#212121"
android:textSize="14sp"
android:ellipsize="end"
android:id="#+id/tv_operator_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="BSNL"
android:layout_toRightOf="#+id/iv_recharge_provider_icon"
android:layout_centerInParent="true"/>
<View
android:layout_below="#id/iv_recharge_provider_icon"
android:id="#+id/divider0"
android:background="#eeeeee"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#+id/iv_recharge_provider_icon"
/>
</RelativeLayout>
add android:nestedScrollingEnabled="false" in RecyclerView
Probably I am missing something here, but I am animating a recyclerview to outside of its container and when it is in the final position, the click events are not triggered, neither the scroll works...
I am using the ObjectAnimator to translate it, so I thought the clickable areas were also translated. Here is the relevant code:
The Fragment
public class SlideListFragment extends Fragment {
private Button slideButton;
private RecyclerView listToSlide;
private DummyListAdapter listAdapter;
private LinearLayout listContainer;
public static SlideListFragment newInstance() {
return new SlideListFragment();
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.slide_list_fragment, container, false);
slideButton = root.findViewById(R.id.slide_up_btn);
slideButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
slideUpRoomsList();
}
});
listToSlide = root.findViewById(R.id.list_to_slide);
listContainer = root.findViewById(R.id.list_container);
setupList();
return root;
}
private void setupList() {
GridLayoutManager layoutManager = new GridLayoutManager(this.getContext(), 1);
layoutManager.setReverseLayout(true);
listToSlide.setLayoutManager(layoutManager);
listAdapter = new DummyListAdapter(this.getContext());
listToSlide.setAdapter(listAdapter);
setListData(5);
}
private void setListData(int i) {
ArrayList<DummyModel> items = new ArrayList<>();
for (int j = 0; j < i; j++) {
items.add(new DummyModel(j, "TEXT" + j));
}
listAdapter.refreshItems(items);
}
private void slideUpRoomsList() {
float height = listContainer.getHeight();
ObjectAnimator showAnimation = ObjectAnimator.ofFloat(listContainer, "translationY", -height);
showAnimation.setDuration(500);
showAnimation.start();
}
}
The Fragment Layout
<?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:id="#+id/slidelist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:context=".ui.slidelist.SlideListFragment">
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" />
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#FF0000"
android:clipChildren="false"
android:clipToPadding="false"
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/guideline">
<LinearLayout
android:id="#+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_to_slide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/slide_up_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="SlideUp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The Adapter
public class DummyListAdapter extends RecyclerView.Adapter<DummyListAdapter.ViewHolder> {
private WeakReference<Context> mContext;
private ArrayList<DummyModel> data;
public DummyListAdapter(Context ctx) {
mContext = new WeakReference<>(ctx);
}
#NonNull
#Override
public DummyListAdapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dummy_list_item, parent, false);
DummyListAdapter.ViewHolder vh = new DummyListAdapter.ViewHolder(v);
return vh;
}
#Override
public void onBindViewHolder(#NonNull DummyListAdapter.ViewHolder holder, int position) {
// get element from your dataset at this position
final DummyModel item = data.get(position);
// replace the contents of the view with that element
holder.labelTV.setText(item.getText());
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext.get(), "Item Clicked: "+ item.getText(), Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getItemCount() {
return data != null ? data.size() : 0;
}
public void refreshItems(ArrayList<DummyModel> items) {
this.data = items;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView labelTV;
public ViewHolder(View itemView) {
super(itemView);
this.labelTV = itemView.findViewById(R.id.label_tv);
}
}
}
The List Item Layout
<?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="wrap_content">
<TextView
android:id="#+id/label_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
android:textSize="20sp"
android:textColor="#0000FF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
What is happening in this case?
UPDATE
I am doing some debug and I noticed that the problem is because the end position is outside the list container. If I translate inside the container, it works properly. So my new question is: how can I translate a view outside of the container, while still having the click events triggered?
Basically, I just gave up on this approach. I changed my layout so it list has space to show up inside its container.
i set on click on the card view when i click on the card view the fragment is shown on the activity i assume that but the fragment is not shown the onclick of cardview is working but fragment is not shown i try alot but no solution i do not know why this happen. There is no error also but my fragment is not shown even no error Advance thanlks
here's code
Activity
public class SubmitAddActivity extends AppCompatActivity implements CallbackFromFragment {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.submitadd_layout);
findViewById(R.id.choose_category_layout).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("bullhead", "onClick: hellow rodl ");
fragmentTransaction=getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.container,fragmentUsage);
fragmentTransaction.commit();
fragmentUsage.setTYPE(1);
}
});
submitbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
settingToolbar();
}
#Override
public void setValues(int type, String value) {
if(type==1)
{
fragmentTransaction.remove(fragmentUsage);
category=value;
}
else if(type==2)
{
fragmentTransaction.remove(fragmentUsage);
location=value;
}
}
}
Activity layout
<ScrollView
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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/containerfragments"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.asad.taleembazar.activities.HomeActivity">
<include
layout="#layout/cardview_choose_category_submitadds"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"
/>
</FrameLayout>
</ScrollView>
fragment
public class SelectFragment extends Fragment implements com.asad.taleembazar.adpaters.callback {
private SelectCategorySubmitAddAdapter adapter;
private RecyclerView.LayoutManager layoutManager;
private ArrayList<String> arrayList=new ArrayList<>();
CallbackFromFragment communication;
int type;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public SelectFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_select_category_submit,container,false);
arrayList.add("Cars");
arrayList.add("Mobiles");
arrayList.add("Bags");
RecyclerView recyclerViewforsubmitadd = (RecyclerView)view.findViewById(R.id.recyclerview_for_categoriessubmit);
layoutManager = new LinearLayoutManager(getActivity());
recyclerViewforsubmitadd.setLayoutManager(layoutManager);
recyclerViewforsubmitadd.setHasFixedSize(true);
adapter = new SelectCategorySubmitAddAdapter(arrayList);
adapter.setOnClick(this);
recyclerViewforsubmitadd.setAdapter(adapter);
return view;
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
communication = (CallbackFromFragment) context;
}
#Override
public void onClick(int adapterPosition) {
if(type==1)
communication.setValues(1,arrayList.get(adapterPosition));
else if(type==2)
communication.setValues(1,arrayList.get(adapterPosition));
}
public void setTYPE(int i)
{
type=i;
}
}
match_parent of your container Framelayout won't work inside your ScrollView. You can either set android:fillViewport="true" in your ScrollView or You can set a fixed height for your container.
Try below code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:fillViewport="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/containerfragments"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.asad.taleembazar.activities.HomeActivity">
<include
layout="#layout/cardview_choose_category_submitadds"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/container"
/>
</FrameLayout>
</ScrollView>
In my app i am using this library
https://github.com/DmitryMalkovich/circular-with-floating-action-button
to implement progress bar with floating action button. Its working on activity but when i included this layout in my fragment's layout progress bar doesn't show.
Here is my code for better explanation
Please guide me where i am going wrong
Any help will be appreciated.
customlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
>
<com.dmitrymalkovich.android.ProgressFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clickable="true">
<ProgressBar
android:id="#+id/progressbar"
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/transparent_logo"
app:backgroundTint="#color/bg_color"
android:layout_centerInParent="true"
/>
</com.dmitrymalkovich.android.ProgressFloatingActionButton>
</RelativeLayout>
fragmentlayout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layoutcontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="bg_color"
>
<include
layout="#layout/customlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="#layout/otherlayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
I am hiding and showing the parent layout of customlayout.xml on runtime when i get data from serivice, before service call i SHOW it with View.VISIBLE and after service call i HIDE it with View.GONE
UPDATED
Java code
Fragment
public class MyFragment extends Fragment {
private Context context;
//root view of layout
View rootView;
private static final String ARG_PARAM1 = "Class";
private String screen_title;
private String URL = "";
public MyFragment() {
// Required empty public constructor
}
public static MyFragment newInstance(String param1) {
MyFragmentfragment = new MyFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity();
if (getArguments() != null) {
screen_title = getArguments().getString(ARG_PARAM1);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragmentlayout, container, false);
//find views by ids
getData();
return rootView;
}
private void getData() {
CustomClass.getInstance(context, rootView).show();
//service call
//on getting response from serivce (have implemented a listener here)
CustomClass.getInstance(context, rootView).hide(); }
#Override
public void onAttach(Context context) {
super.onAttach(context);
}
#Override
public void onDetach() {
super.onDetach();
}
CustomClass
public class CustomClass {
private ProgressBar mProgressBar;
private FloatingActionButton mFab;
private RelativeLayout parentLayout;
private LayoutInflater inflater;
private static CustomClass custom;
private CustomClass (Context context) {
findViewsById(context);
}
private CustomClass (View view) {
findViewsById(view);
}
public static CustomClass getInstance(Context context, View view) {
custom = new CustomClass (view);
custom.setPColor(context);
return custom;
}
public static CustomClass getInstance(Context context) {
custom = new CustomClass (context);
custom.setPColor(context);
return custom;
}
private void setPColor(Context context) {
if (mProgressBar != null)
mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(context, R.color.bluecolor), android.graphics.PorterDuff.Mode.MULTIPLY);
}
private void findViewsById(View view) {
if (view != null) {
mProgressBar = (ProgressBar) view.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) view.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) view.findViewById(R.id.rl_progress_fab_container);
}
}
private void findViewsById(Context context) {
Activity activity = (Activity) context;
if (activity != null) {
mProgressBar = (ProgressBar) activity.findViewById(R.id.custom_progressbar);
mFab = (FloatingActionButton) activity.findViewById(R.id.custom_floatingActionButton);
parentLayout = (RelativeLayout) activity.findViewById(R.id.rl_progress_fab_container);
}
}
public void show() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.VISIBLE);
}
public void hide() {
if (custom.parentLayout != null)
custom.parentLayout.setVisibility(View.GONE);
}
make your customlayout at the bottom with the parent layout.
so your z index for that layout is at the top and it will be visible and gone that can be seen by you.
You need to use CoordinatorLayout with FAB .
Just put your FAB inside CoordinatorLayout.
As you can see library sample code suggests to use it too.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dmitrymalkovich.android.progressfabsample.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.dmitrymalkovich.android.ProgressFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:clickable="true"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_backup_black_24dp"
app:backgroundTint="#color/colorFab" />
<ProgressBar
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.dmitrymalkovich.android.ProgressFloatingActionButton>
<com.dmitrymalkovich.android.ProgressFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:clickable="true">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_backup_black_24dp"
app:backgroundTint="#color/colorFab" />
<ProgressBar
style="#style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.dmitrymalkovich.android.ProgressFloatingActionButton>
try this:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragmentlayout, container, false);
//find views by ids
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
getData();
}
});
return rootView;
}
or
private void getData() {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
CustomClass.getInstance(context, rootView).show();
CustomClass.getInstance(context, rootView).hide();
}
});
}