I have line chart inside scrollView, all of my data is 7 points, I have lag by scrolling screen,
I try with nestedScrollview or disable chart accessibility but still I have lag.
when chart has no data, scrollView is very smooth, but when i set data on chart, i have bad scrolling
this is setup class
public class SetupCharts {
public LineData drawChart(Context context, ArrayList<Entry> entries, LineChart chart, String[] labels) {
if (entries.size() > 0) {
//customization dataSet Settings
LineDataSet set = new LineDataSet(entries, "");
set.setAxisDependency(YAxis.AxisDependency.LEFT);
set.setDrawValues(true);
set.setLineWidth(3f);
set.setDrawCircles(true);
set.setValueTextSize(12f);
set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
set.setValueTextColor(context.getResources().getColor(R.color.progress));
set.setColor(context.getResources().getColor(R.color.progress));
set.setCircleColor(context.getResources().getColor(R.color.progress));
//customization chart settings
chart.setNoDataText("No data");
chart.setTouchEnabled(false);
chart.setDragEnabled(false);
chart.setDrawGridBackground(false);
chart.getDescription().setEnabled(false);
chart.setPinchZoom(false);
chart.setNestedScrollingEnabled(false);
chart.getLegend().setEnabled(false);
if (labels != null) {
//customization XAxis settings
XAxis x1 = chart.getXAxis();
x1.setTextColor(context.getResources().getColor(R.color.progress));
x1.setDrawGridLines(false);
x1.setAvoidFirstLastClipping(true);
x1.setPosition(XAxis.XAxisPosition.BOTTOM);
x1.setValueFormatter(new IndexAxisValueFormatter(labels));
x1.setLabelCount(labels.length, true);
}
//customization YAxis settings
YAxis y1 = chart.getAxisLeft();
y1.setDrawLabels(false);
y1.setTextColor(Color.BLACK);
y1.setDrawGridLines(false);
YAxis y2 = chart.getAxisRight();
y2.setEnabled(false);
LineData data = new LineData(set);
//set custom font
Typeface face = Typeface.createFromAsset(context.getAssets(), "Shabnamn.ttf");
data.setValueTypeface(face);
chart.getXAxis().setTypeface(face);
return data;
}else
return null;
}
}
and in activity
public void parseResponse(String response){
ArrayList<Entry> entries = new ArrayList<>();
try {
JSONObject object = new JSONObject(response);
JSONArray array = object.getJSONArray("summary");
labels = new String[array.length()];
int j = 0;
for (int i = array.length() - 1; i >= 0; i--) {
JSONObject object1 = array.getJSONObject(i);
int y = object1.getInt("burnt_calory");
entries.add(new Entry(j, y));
date = object1.getString("at_date");
j++;
}
} catch (JSONException e) {
e.printStackTrace();
Log.i("action response catch", "error");
}
LineData data = new
SetupCharts().drawChart(ActionActivity.this,entries, chart , labels);
chart.setData(data);
chart.animateY(55*35, Easing.Linear);
}
and this is xml file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/constraintLayout"
android:layout_marginBottom="16dp"
android:background="#color/darkWhite"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">
<Button
android:id="#+id/btnActionDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/green_btn_border"
android:drawableStart="#drawable/ic_arrow_drop_down_black_24dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="#color/colorWhite"
android:textSize="12sp"
app:layout_constraintWidth_percent="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/txtActionTitle"
android:text="#string/steps"
android:textSize="14sp"
app:layout_constraintTop_toTopOf="#id/btnActionDate"
app:layout_constraintBottom_toBottomOf="#id/btnActionDate"
app:layout_constraintEnd_toEndOf="parent"/>
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:elevation="2dp"
android:indeterminate="true"
android:indeterminateTint="#color/progress"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="#id/powerSportCard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:id="#+id/car12"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="20dp"
android:elevation="2dp"
app:cardCornerRadius="8dp"
app:layout_constraintTop_toBottomOf="#+id/btnActionDate">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtProgress"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:gravity="center"
android:text="#string/daily_activity_amount"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="#+id/arc_progress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="#+id/arc_progress"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:arc_angle="230"
app:arc_bottom_text="60 دقیقه"
app:arc_bottom_text_size="20dp"
app:arc_finished_color="#color/progress"
app:arc_text_color="#color/BlackColor"
app:arc_text_size="30dp"
app:arc_unfinished_color="#color/Gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/card13"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="20dp"
android:elevation="2dp"
app:cardCornerRadius="8dp"
app:layout_constraintTop_toBottomOf="#+id/car12">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtChartTitle"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:text="#string/cal_history"
android:textSize="12sp" />
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/lineChart2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView12"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toStartOf="#+id/cardView3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/card13">
<TextView
android:id="#+id/txtCalories"
android:drawableTop="#drawable/ic_carbohydrates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView3"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toStartOf="#+id/cardView11"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/cardView12"
app:layout_constraintTop_toTopOf="#+id/cardView12">
<TextView
android:id="#+id/txtKm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_racing_car"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardView11"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginStart="8dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/cardView3"
app:layout_constraintTop_toTopOf="#+id/cardView12">
<TextView
android:id="#+id/txtTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_alarm_clock"
android:layout_gravity="center"
android:drawablePadding="8dp"
android:gravity="center" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/walkSportCard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toStartOf="#+id/powerSportCard"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView12">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/Types_of_running"
android:textSize="12sp"
android:drawableTop="#drawable/ic_climb"
android:layout_gravity="center"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/powerSportCard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/walkSportCard"
app:layout_constraintTop_toTopOf="#+id/walkSportCard">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/Powerful_exercises"
android:textSize="12sp"
android:drawableTop="#drawable/ic_weight"
android:layout_gravity="center"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/dailyCard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="24dp"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/competitionSportCard"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/walkSportCard">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/daily_activity"
android:textSize="12sp"
android:drawableTop="#drawable/ic_bathtub"
android:layout_gravity="center"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/competitionSportCard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:cardCornerRadius="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/dailyCard"
app:layout_constraintTop_toTopOf="#+id/dailyCard">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/Competitive_sports"
android:textSize="12sp"
android:drawableTop="#drawable/ic_podium"
android:layout_gravity="center"
android:drawablePadding="10dp"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"/>
</androidx.cardview.widget.CardView>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/darkWhite"
android:elevation="0dp"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay">
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="#+id/sportFrame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Related
I have 2 RecyclerViews that uses the same XML file to inflate views through the adapter.
One RecyclerView does catch clicks while the other doesn't.
The first RecyclerView is on another fragment and the code is similar to the second RecyclerView.
I have tried a lot of changes to the XML file(MaterialCardView) such as removing clickable attribute or changing the layout_weight to be 1 on the card but all of them didn't work.
Also, I can't understand why it would work only on 1 with the same settings on the other.
Here is the code for the second part which is not working:
Fragment - section of matter
list = view.findViewById(R.id.user_display_details_rv); //Getting the RecyclerView
list.setHasFixedSize(true);
int numOfColumns = 2;
list.setLayoutManager(new GridLayoutManager(getContext(), numOfColumns,GridLayoutManager.VERTICAL,false));
adapter = new UserDisplayDetailsAdapter(viewModel,getLayoutInflater());
list.setAdapter(adapter);
list.addItemDecoration(new RecyclerView.ItemDecoration() {
#Override
public void getItemOffsets(#NonNull Rect outRect, #NonNull View view, #NonNull RecyclerView parent, #NonNull RecyclerView.State state) {
outRect.set(5,20,5,20);
}
});
adapter.setOnItemClickListener((v,pos)->{
String pollId = Objects.requireNonNull(viewModel.getUserFilledPolls().get(pos).getPollId());
Navigation.findNavController(v).navigate(FragmentUserDisplayDetailsDirections.actionFragmentUserDisplayDetailsToFragmentOtherUserPoll(pollId,userId));
});
Adapter
public class UserDisplayDetailsAdapter extends RecyclerView.Adapter<UserDisplayDetailsHolder> {
UserDisplayDetailsViewModel viewModel;
LayoutInflater layoutInflater;
OnItemClickListener onItemClickListener;
public UserDisplayDetailsAdapter(UserDisplayDetailsViewModel viewModel, LayoutInflater layoutInflater) {
this.viewModel = viewModel;
this.layoutInflater = layoutInflater;
}
#NonNull
#Override
public UserDisplayDetailsHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) MyApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.poll_list_square,parent,false);
return new UserDisplayDetailsHolder(view,onItemClickListener);
}
#Override
public void onBindViewHolder(#NonNull UserDisplayDetailsHolder holder, int position) {
Poll poll = Objects.requireNonNull(viewModel.getUserFilledPolls().get(position));
holder.bind(poll);
}
#Override
public int getItemCount() {
if(viewModel.getUserFilledPolls() == null){
return 0;
}
return viewModel.getUserFilledPolls().size();
}
public void setOnItemClickListener(OnItemClickListener listener){
this.onItemClickListener = listener;
}
}
Holder
public class UserDisplayDetailsHolder extends RecyclerView.ViewHolder {
MaterialTextView pollsName;
ShapeableImageView icon;
public UserDisplayDetailsHolder(#NonNull View itemView, OnItemClickListener onItemClickListener) {
super(itemView);
pollsName = itemView.findViewById(R.id.homescr_poll_pollName);
icon=itemView.findViewById(R.id.homescr_poll_icon);
itemView.setOnClickListener(v->{
int pos = getAdapterPosition();
onItemClickListener.onItemClick(v,pos);
});
}
public void bind(Poll poll) {
pollsName.setText(poll.getPollName());
}
}
Common XML
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
android:id="#+id/homescr_btn_poll"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:layout_width="110dp"
android:layout_height="90dp"
android:layout_gravity="center"
app:cardBackgroundColor="#color/primeOrng"
app:cardCornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:strokeWidth="2dp"
android:theme="#style/Theme.MaterialComponents.Light">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="horizontal">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_mainImage"
android:layout_width="60dp"
android:layout_height="40dp"
android:scaleType="fitStart"
app:strokeWidth="0dp"
app:srcCompat="#drawable/ic_poll" />
<Space
android:id="#+id/homescr_poll_space"
android:layout_width="10dp"
android:layout_height="wrap_content" />
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_icon"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="end"
app:srcCompat="#drawable/ic_feed_arrow"
app:strokeWidth="0dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homescr_poll_pollName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:text="#string/poll_name"
android:textAppearance="?attr/textAppearanceHeadline6"
android:textColor="#color/white"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homescr_poll_doneImage"
android:layout_width="60dp"
android:layout_height="50dp"
android:visibility="gone"
app:srcCompat="#drawable/done_nobg" />
</com.google.android.material.card.MaterialCardView>
Working Fragment XML(Catching clicks on RecyclerView)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
app:cardElevation="0dp"
app:strokeColor="#color/stroke_color">
tools:context=".FragmentHomeScreen">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/homeScreen_logo"
android:layout_width="306dp"
android:layout_height="160dp"
android:src="#drawable/logo__nobg_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homeScr_text_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="Hello, "
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeScreen_logo" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/homeScr_text_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="80dp"
android:fontFamily="sans-serif-black"
android:gravity="start"
android:text="User Name"
android:maxLines="1"
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/homeScr_text_title"
app:layout_constraintTop_toBottomOf="#+id/homeScreen_logo" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/home_layout_const"
android:layout_width="350dp"
android:layout_height="250dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="10dp"
android:foregroundGravity="center_horizontal"
android:paddingLeft="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homeScr_text_name">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/home_layout_poll_refresh"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_poll_rv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="#color/white"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_line"
android:layout_width="350dp"
android:layout_height="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="90dp"
android:backgroundTint="#978F8F"
app:cornerRadius="100px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_feed"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/black"
android:drawableTop="#drawable/ic_feed"
android:fontFamily="sans-serif-medium"
android:text="FEED"
android:textColor="#color/primeOrng"
android:textSize="14dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/homescr_btn_map"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/homescr_btn_line"
app:strokeColor="#color/black"
app:strokeWidth="2dp" />
<com.google.android.material.button.MaterialButton
android:id="#+id/homescr_btn_map"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:backgroundTint="#color/black"
android:drawableTop="#drawable/ic_map"
android:fontFamily="sans-serif-medium"
android:text="#string/map"
android:textColor="#color/primeOrng"
android:textSize="14dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/homescr_btn_feed"
app:layout_constraintTop_toBottomOf="#+id/homescr_btn_line"
app:strokeColor="#color/black"
app:strokeWidth="2dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
NOT Working Fragment XML(NOT Catching clicks on RecyclerView)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:scrollbars="vertical"
android:scrollbarSize="3dp"
android:scrollbarStyle="insideInset"
tools:context=".feed.FragmentUserDisplayDetails">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="#+id/user_display_details_img_main"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.App.CornerSize50Percent"
app:srcCompat="#drawable/avatar"
app:strokeColor="#color/white"
app:strokeWidth="1dp" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-black"
android:gravity="center"
android:text="User Name"
android:textColor="#color/white"
android:textSize="32dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_display_details_img_main" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/user_dusplay_details_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_display_details_txt_username">
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:drawableStart="#drawable/ic_account"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="#string/email"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/ic_white_location"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:maxLines="2"
android:paddingLeft="20dp"
android:text="address"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_education"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/ic_education"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="education"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/user_display_details_txt_gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:drawableStart="#drawable/sex_icon"
android:drawablePadding="10dp"
android:fontFamily="sans-serif-light"
android:gravity="left"
android:paddingLeft="20dp"
android:text="SEX"
android:textColor="#color/white"
android:textSize="28dp"
android:textStyle="bold" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/user_display_details_poll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/textviewbg">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/user_display_details_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.button.MaterialButton
android:id="#+id/feed_back_btn"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:backgroundTint="#color/black"
android:fontFamily="sans-serif"
android:text="BACK "
android:textSize="20sp"
app:cornerRadius="35dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/user_dusplay_details_layout"
app:strokeColor="#color/primeOrng"
app:strokeWidth="1dp" />
<ProgressBar
android:id="#+id/user_display_details_progress_bar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I have a scrollView in my fragment that only works if I open the fragment once, then close it and then reopen it. At first, it does not scroll at all and after the described steps it works perfectly. I have already tried wrapping the constraintLayout in a tableLayout, LinearLayout, and also used the scrollView as a top level layout. I cannot find anything about this on google.
Please help
<?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"
tools:context=".LightPack.LightSettings"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="24dp"
android:fontFamily="#font/montserrat"
android:text="Keet at:"
android:textColor="#FFFFFF"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/circular_range_slider" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:checkedButton="#id/radioButton"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="On/Off"
android:textColor="#FFFFFF" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Time Schedule"
android:textColor="#FFFFFF" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Keep around"
android:textColor="#FFFFFF" />
</RadioGroup>
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:text="ON"
android:textColor="#FFFFFF"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="#+id/radioGroup"
app:layout_constraintTop_toTopOf="#+id/textView" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:text="Air Condition"
android:textColor="#FFFFFF"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="#+id/radioGroup"
app:layout_constraintTop_toBottomOf="#+id/radioGroup" />
<com.bikcrum.circularrangeslider.CircularRangeSlider
android:id="#+id/circular_range_slider"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="50dp"
app:borderColor="#838383"
app:borderWidth="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:max="24">
</com.bikcrum.circularrangeslider.CircularRangeSlider>
<com.bikcrum.circularrangeslider.CircularRangeSlider
android:id="#+id/circular_range_slider2"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="32dp"
app:borderColor="#838383"
app:borderWidth="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4"
app:max="24">
</com.bikcrum.circularrangeslider.CircularRangeSlider>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/montserrat"
android:text="Temperature:"
android:textColor="#FFFFFF"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tempDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:fontFamily="#font/montserrat"
android:text="24 C"
android:textColor="#FFFFFF"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:ems="10"
android:fontFamily="#font/montserrat"
android:hint="Temp"
android:inputType="number"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView4"
app:layout_constraintTop_toTopOf="#+id/textView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
Ok so I found the answer.
I used the fragment in a viewpager but it was a custom one.
public class CustomViewPager extends ViewPager {
public CustomViewPager(#NonNull Context context) {
super(context);
}
public CustomViewPager(#NonNull Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}
if (height != 0) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
After goind back to the normal one, everathing worked again.
In Fragment, I made initUI() and initializes image view, but getting error.Not able why it is getting an error. I'm providing Fragment's initUI() and XML files.
Error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at novumlogic.payment.home.CateFragment.initUI(CateFragment.java:95)
at novumlogic.payment.home.CateFragment.onCreate(CateFragment.java:61)
Fragment
private void initUI() {
//#SuppressLint("ResourceType") AppCompatTextView tvDay = ((AppCompatTextView) rootView.findViewById(R.id.imgSendMoney,16.0F));
//AppCompatTextView tvDay1 = (AppCompatTextView) rootView.findViewById(R.id.imgReceiveMoney);
ViewCompat.setElevation((ImageView) rootView.findViewById(R.id.imgSendMoney), 16.0F);
ViewCompat.setElevation((ImageView)rootView.findViewById(R.id.imgReceiveMoney), 16.0F);
/*((AppCompatImageView)root.findViewById(R.id.imgNotification)).setOnClickListener((View.OnClickListener) new View.OnClickListener() {
public final void onClick(View it) {
Toast.makeText((Context)HomeFragment.this, (CharSequence)"Notification List", 0).show();
}
});*/
((CardView)rootView.findViewById(R.id.cardSendMoney)).setOnClickListener((View.OnClickListener)(new View.OnClickListener() {
public final void onClick(View it) {
Intent k = new Intent(getContext(), SendMoneyActivity.class);
startActivity(k);
//HomeFragment.this.startActivity(new Intent((Context)HomeFragment.this.getActivity(), SendMoneyActivity.class));
}
}));
CardView card_view = (CardView) rootView.findViewById(R.id.cardReceiveMoney);
card_view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do whatever you want to do on click (to launch any fragment or activity you need to put intent here.)
Intent k = new Intent(getContext(), ReceiveMoneyActivity.class);
startActivity(k);
}
});
((RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts)).setItemViewCacheSize(0);
((RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts)).setHasFixedSize(true);
RecyclerView var10000 = (RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts);
Intrinsics.checkExpressionValueIsNotNull(var10000, "root.recyclerBankAccounts");
var10000.setLayoutManager((RecyclerView.LayoutManager)(new LinearLayoutManager((Context)this.getActivity(), 0, false)));
BankAccountsListAdapter bankAccountsAdapter = new BankAccountsListAdapter();
var10000 = (RecyclerView)rootView.findViewById(R.id.recyclerBankAccounts);
Intrinsics.checkExpressionValueIsNotNull(var10000, "root.recyclerBankAccounts");
var10000.setAdapter((RecyclerView.Adapter)bankAccountsAdapter);
}
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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgLogo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginBottom="#dimen/margin_16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/fee_logo" />
<android.support.v7.widget.AppCompatTextView
style="#style/BoldTitleStyle"
android:layout_margin="#dimen/margin_8"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/imgLogo"
app:layout_constraintStart_toEndOf="#id/imgLogo"
app:layout_constraintTop_toTopOf="#+id/imgLogo" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginEnd="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_bell_icon" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="#id/imgNotification"
app:layout_constraintTop_toTopOf="#id/imgNotification"
app:srcCompat="#drawable/badge" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/margin_8"
android:text="02"
android:textColor="#color/colorPrimary"
android:textSize="#dimen/text_tiny_8"
app:layout_constraintBottom_toBottomOf="#id/imgBadge"
app:layout_constraintEnd_toEndOf="#id/imgBadge"
app:layout_constraintStart_toStartOf="#id/imgBadge"
app:layout_constraintTop_toTopOf="#id/imgBadge" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/appbar">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtMyBankAccounts"
style="#style/BoldSubTitleStyle"
android:text="#string/title_my_bank_accounts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerBankAccounts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="#+id/cardReceiveMoney"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtMyBankAccounts" />
<android.support.v7.widget.CardView
android:id="#+id/cardSendMoney"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_8"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginRight="#dimen/margin_4"
android:layout_marginBottom="#dimen/margin_16"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toStartOf="#+id/cardReceiveMoney"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/recyclerBankAccounts">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="#dimen/margin_8">
<ImageView
android:id="#+id/imgSendMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginEnd="#dimen/margin_8"
android:background="#drawable/send_money_icon"
android:padding="#dimen/margin_8"
app:srcCompat="#drawable/ic_arrow_forward" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/poppins_bold"
android:padding="#dimen/margin_8"
android:text="#string/msg_send_money"
android:textColor="#color/colorSecondary" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/cardReceiveMoney"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_4"
android:layout_marginTop="#dimen/margin_16"
android:layout_marginRight="#dimen/margin_8"
android:layout_marginBottom="#dimen/margin_16"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/cardSendMoney"
app:layout_constraintTop_toBottomOf="#id/recyclerBankAccounts">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="#dimen/margin_8">
<ImageView
android:id="#+id/imgReceiveMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8"
android:layout_marginEnd="#dimen/margin_8"
android:background="#drawable/receive_money_icon"
android:padding="#dimen/margin_8"
app:srcCompat="#drawable/ic_arrow_back" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/poppins_bold"
android:padding="#dimen/margin_8"
android:text="#string/msg_receive_money"
android:textColor="#color/colorSecondary" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtSendMoneyTo"
style="#style/BoldSubTitleStyle"
android:layout_marginTop="#dimen/margin_22"
android:text="#string/label_send_money_to"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardSendMoney" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txtSendMoneyToViewAll"
style="#style/BoldSubTitleStyle"
android:layout_margin="#dimen/margin_8"
android:fontFamily="#font/poppins_medium"
android:text="#string/label_view_all"
android:textSize="#dimen/text_small_14"
app:layout_constraintBaseline_toBaselineOf="#+id/txtSendMoneyTo"
app:layout_constraintEnd_toEndOf="#id/cardReceiveMoney" />
<android.support.v7.widget.CardView
android:id="#+id/linearSendMoneyTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:cardCornerRadius="#dimen/margin_16"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/txtSendMoneyTo">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/imgAddContact"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_add_circle"
app:contactName="Add New"
app:hasBackgroundRing="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem1"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Alice"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/imgAddContact"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Bob"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/contactItem3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem1"
app:layout_constraintTop_toTopOf="parent" />
<novumlogic.payment.customview.DashboardContactItem
android:id="#+id/contactItem3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_8"
app:contactImage="#drawable/ic_avatar"
app:contactName="Emily"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imgViewMore"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem2"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imgViewMore"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="#+id/contactItem3"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_keyboard_arrow_right" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/collaps"
android:fitsSystemWindows="true"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
>
<FrameLayout
android:id="#+id/institutions_tab_fragments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.cooltechworks.views.shimmer.ShimmerRecyclerView
android:id="#+id/recycler_view_institutions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/noDataFound"
android:visibility="invisible"
>
<include
layout="#layout/no_data_found"
>
</include>
</LinearLayout>
</FrameLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Your rootView is null.
Looking at the stacktrace, you're calling initUI() in onCreate(). It is too early. If your rootView is the usual view as inflated in onCreateView(), you need to call initUI() in onCreateView() after inflation, or onViewCreated(), and actually init rootView before that.
I have created one XML with 4 CardView contains 4 RadioButton and other layouts as follow:
fragment_list_of_transport.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<android.support.v4.widget.NestedScrollView 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.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_1"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_1"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_1" />
<ImageView
android:id="#+id/image_truck_1"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_1"
app:layout_constraintStart_toEndOf="#+id/radio_button_1"
app:layout_constraintTop_toTopOf="#+id/title_text_view_1"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_1"
app:layout_constraintTop_toBottomOf="#+id/image_view_1" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
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/title_text_view_1"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/parent_card_2"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_1">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_2"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_2" />
<ImageView
android:id="#+id/image_truck_2"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_2"
app:layout_constraintStart_toEndOf="#+id/radio_button_2"
app:layout_constraintTop_toTopOf="#+id/title_text_view_2"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_2"
app:layout_constraintTop_toBottomOf="#+id/image_view_2" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
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/title_text_view_2"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_3"
android:layout_width="0dp"
android:background="?attr/selectableItemBackground"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_2">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_3"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_3" />
<ImageView
android:id="#+id/image_truck_3"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_3"
app:layout_constraintStart_toEndOf="#+id/radio_button_3"
app:layout_constraintTop_toTopOf="#+id/title_text_view_3"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_3"
app:layout_constraintTop_toBottomOf="#+id/image_view_3" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
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/title_text_view_3"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:clickable="true"
android:focusable="true"
android:id="#+id/parent_card_4"
android:background="?attr/selectableItemBackground"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginEnd="#dimen/_5sdp"
android:layout_marginBottom="#dimen/_10sdp"
app:cardCornerRadius="#dimen/_5sdp"
app:cardElevation="#dimen/_5sdp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/parent_card_3">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_view_4"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_transport_list_height"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/now_courier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioButton
android:id="#+id/radio_button_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="#+id/image_truck_4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/image_truck_4" />
<ImageView
android:id="#+id/image_truck_4"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/app_name"
app:layout_constraintBottom_toBottomOf="#+id/title_text_view_4"
app:layout_constraintStart_toEndOf="#+id/radio_button_4"
app:layout_constraintTop_toTopOf="#+id/title_text_view_4"
app:srcCompat="#drawable/ic_truck" />
<TextView
android:id="#+id/title_text_view_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="Small express under 10 items"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/image_truck_4"
app:layout_constraintTop_toBottomOf="#+id/image_view_4" />
<Button
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_30sdp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/background_round_colors"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:text="#string/button_next"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
android:textColor="#color/white"
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/title_text_view_4"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Output:
I want to manage RadioButton on click of both CardView and RadioButton , I have used following code:
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
mBinding.radioButton1.setChecked(true);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_2:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(true);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_3:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(true);
mBinding.radioButton4.setChecked(false);
break;
case R.id.parent_card_4:
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(true);
break;
}
}
}
Is there any best way to manage it?
I don't easiest way then following (If you have easy way then I will accept it.):
/**
* A simple {#link Fragment} subclass.
*/
public class FragmentListTransport extends Fragment implements View.OnClickListener {
FragmentListOfTransportBinding mBinding;
public FragmentListTransport() {
// Required empty public constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_list_of_transport, container, false);
mBinding.parentCard1.setOnClickListener(this);
mBinding.parentCard2.setOnClickListener(this);
mBinding.parentCard3.setOnClickListener(this);
mBinding.parentCard4.setOnClickListener(this);
mBinding.radioButton1.setOnClickListener(this);
mBinding.radioButton2.setOnClickListener(this);
mBinding.radioButton3.setOnClickListener(this);
mBinding.radioButton4.setOnClickListener(this);
return mBinding.getRoot();
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.parent_card_1:
case R.id.radio_button_1:
clickedRadioButton(mBinding.radioButton1);
break;
case R.id.parent_card_2:
case R.id.radio_button_2:
clickedRadioButton(mBinding.radioButton2);
break;
case R.id.parent_card_3:
case R.id.radio_button_3:
clickedRadioButton(mBinding.radioButton3);
break;
case R.id.parent_card_4:
case R.id.radio_button_4:
clickedRadioButton(mBinding.radioButton4);
break;
}
}
private void clickedRadioButton(RadioButton radioButton) {
mBinding.radioButton1.setChecked(false);
mBinding.radioButton2.setChecked(false);
mBinding.radioButton3.setChecked(false);
mBinding.radioButton4.setChecked(false);
radioButton.setChecked(true);
}
}
If anyone has easiest way then this, please post answer. I will accept.
I'm trying to create a layout for my Fragment . Here is my xml layout.
Fragment_profil.xml
<FrameLayout 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="com.example.boby.srsly.ProfilFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
But, when i run it i only see white background, i mean because this is bottomnavigationview i only can see the navigation from what i write above. How can i fix it, is there something missing ? Thanks in advance and sorry for my bad english.
Here is my ProfilFragment.java
public class ProfilFragment extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_profil, container, false);
SharedPreferences mPrefs = this.getActivity().getSharedPreferences("userinfoafterlogin", MODE_PRIVATE); //add key
String response = mPrefs.getString("userinfo", null);
try{
JSONObject json = new JSONObject(response);
json = (JSONObject)json.get("nameValuePairs");
json = (JSONObject)json.get("userData");
json = (JSONObject)json.get("nameValuePairs");
String fullname = (String)json.get("fullname");
String phone = (String)json.get("phone");
String desc = (String)json.get("Deskripsi");
TextView labelfullname = (TextView)v.findViewById(R.id.fullnametext);
TextView labeltelp = (TextView)v.findViewById(R.id.notelptext);
TextView labeldesc = (TextView)v.findViewById(R.id.deskripsitxt);
labelfullname.setText(fullname);
labeltelp.setText(phone);
labeldesc.setText(desc);
return v;
}catch (JSONException e) {
Log.e("MYAPP", "unexpected JSON exception", e);
return v;
}
}
}
Try this
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.027">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/fullnametext"
android:layout_width="144dp"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
android:text="fullnametext"
app:layout_constraintBottom_toTopOf="#+id/notelptext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.716"
app:layout_constraintStart_toEndOf="#+id/fullnameLabel"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.26" />
<TextView
android:id="#+id/fullnameLabel"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="76dp"
android:text="Fullname"
app:layout_constraintBottom_toTopOf="#+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView4"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="64dp"
android:text="No Telp"
app:layout_constraintBottom_toTopOf="#+id/textView6"
app:layout_constraintEnd_toStartOf="#+id/notelptext" />
<TextView
android:id="#+id/notelptext"
android:layout_width="144dp"
android:layout_height="20dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="28dp"
android:text="notelp"
app:layout_constraintBottom_toTopOf="#+id/deskripsitxt"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="117dp"
android:layout_height="23dp"
android:layout_marginEnd="60dp"
android:text="Deskripsi"
app:layout_constraintEnd_toStartOf="#+id/deskripsitxt"
tools:layout_editor_absoluteY="180dp" />
<TextView
android:id="#+id/deskripsitxt"
android:layout_width="144dp"
android:layout_height="63dp"
android:layout_marginBottom="252dp"
android:layout_marginEnd="28dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
OUTPUT