Not able to put recycler view as ExpandableListView header layout - java

I want to display a recycler view inside the ExpandableListView header item.But I am getting an issue my header is not clickable when I put a recycler view in it.
Here is my code:-
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:padding="8dp"
android:background="#color/grey">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="15dp"
android:layout_weight=".25"
android:text="#"
android:textColor="#color/ModeltitleColor" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".65"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/ivRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
/>
</LinearLayout>
<ImageView
android:id="#+id/iv_group_indicator"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_weight=".10"
android:src="#drawable/ic_arrow_drop_down_black_24dp" />
</LinearLayout>
</LinearLayout>
here I am setting the group:-
#Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.zonal_list_group, viewGroup, false);
}
TextView textView = view.findViewById(R.id.lblListHeader);
RecyclerView recyclerView=view.findViewById(R.id.ivRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));
ZoneNameAdapter zoneNameAdapter =new ZoneNameAdapter(zonalSnapShotResponse.keyFigureDataGroups.get(i).zones,context);
recyclerView.setAdapter(zoneNameAdapter);
ImageView imageView = view.findViewById(R.id.iv_group_indicator);
textView.setText(zonalSnapShotResponse.keyFigureDataGroups.get(i).dataGroup);
imageView.setImageResource(R.drawable.ic_arrow_drop_down_black_24dp);
if (b) {
imageView.setRotation(180f);
} else {
imageView.setRotation(0f);
}
return view;
}
getChildItemCount does not get called when I put recycler view in the header.
I have tried multiple solutions but noting worked for me.Please help

Related

Android java - dynamically add ImageViews in LinearLayout

i would like to add to a LinearLayout some imageViews dynamically in my app.
My following code doesn't show errors and prints what it is supposed to on logcat each time an ImageView is added from java code.
My problem is that when i run the app the images don't appear on screen....any idea where i am doing wrong ?
thanks a lot.
public class MesListesFragment extends Fragment {
private RecyclerView mes_listes_recyclerView;
private ArrayList<ListItem> liste_items;
private LinearLayout list_card_categories;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mes_listes_fragment, container, false);
View view2 = inflater.inflate(R.layout.list_item, container, false);
mes_listes_recyclerView = view.findViewById(R.id.mes_listes_recyclerView);
list_card_categories = view2.findViewById(R.id.list_card_recyclerView);
liste_items = new ArrayList<>();
for (int i = 0; i < 10; i ++){
liste_items.add(new ListItem("Liste des ploucs", "18 Août 198" + i));
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
mes_listes_recyclerView.setLayoutManager(linearLayoutManager);
mes_listes_recyclerView.setAdapter(new ListViewAdapter(getContext(), liste_items));
for (int i = 0; i < 8; i++){
ImageView image = new ImageView(getContext());
image.setImageResource(R.drawable.user);
list_card_categories.addView(image);
Log.d("view created", "...");
}
return view;
}
}
Here is the xml, the file's called list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="150dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/list_card_first_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/list_card_textView_nom_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nom de la liste"></TextView>
<TextView
android:id="#+id/list_card_textView_date_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date liste"></TextView>
</LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50">
<LinearLayout
android:id="#+id/list_card_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/list_card_second_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/list_card_first_container"
android:gravity="center"
android:orientation="horizontal"
android:paddingVertical="5dp">
<Button
android:id="#+id/list_card_button_editer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:background="#color/bleu_fb"
android:text="#string/editer"></Button>
<Button
android:id="#+id/list_card_button_supprimer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#android:color/holo_red_light"
android:text="#string/supprimer"></Button>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>

bottom navigation data is not displaying using recyclerview using cardview

Hi in the below code I am working with bottom navigation it contains different option in that one thing is account .If click on the account bottom tab want to display the cardview in recyclerviews
But data is not coming anything. It is displaying empty.
using this below xml to display the content in listview format
accounts.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Fragment_account.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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:background="#color/White">
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardBackgroundColor="#color/slivergray"
app:cardCornerRadius="8dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/White">
<ImageView
android:id="#+id/appImage"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginLeft="16dp"
android:background="#drawable/ic_account_circle_black_24dp"
android:backgroundTint="#color/gray"
android:scaleType="centerCrop"
tools:ignore="ContentDescription"/>
<TextView
android:id="#+id/headingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/appImage"
android:paddingLeft="16sp"
android:paddingRight="16dp"
android:text="Apollo Hospital"
android:textColor="#color/black"
android:textSize="18sp"
tools:ignore="RtlHardcoded"/>
<TextView
android:id="#+id/subHeaderText"
style="#style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headingText"
android:layout_toRightOf="#+id/appImage"
android:paddingLeft="16dp"
android:text="Hospital"
android:paddingRight="16dp"
android:textColor="#color/gray"
android:textSize="15sp"/>
<TextView
android:id="#+id/subHeadingText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/subHeaderText"
android:layout_toRightOf="#+id/appImage"
android:gravity="left"
android:lines="5"
android:maxLines="5"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:text="stories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detailstories_detail"
android:textColor="#color/gray"
android:textSize="14sp"/>
<TextView
android:id="#+id/textViewOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:text="⋮"
android:textColor="#color/gray"
android:layout_marginRight="10dp"
android:textAppearance="?android:textAppearanceLarge"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/subHeadingText">
<LinearLayout
android:layout_width="209dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="30dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:backgroundTint="#color/gray"
android:src="#drawable/ic_account_circle_black_24dp"></ImageView>
<Button
android:id="#+id/action1"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action 1"
android:textColor="#color/gray"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="#drawable/ic_account_circle_black_24dp"
android:layout_marginLeft="50dp"></ImageView>
<Button
android:id="#+id/action2"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action 2"
android:textColor="#color/gray"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
AccountFragment.java:
public class AccountFragement extends Fragment {
public AccountFragement(){
}
RecyclerView rv;
private List<List_Data> list_data;
private MyAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate (R.layout.account, container, false);
rv=(RecyclerView) rootView.findViewById(R.id.recyclerview);
//rv.setHasFixedSize(true);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
list_data=new ArrayList<>();
adapter=new MyAdapter(list_data,getContext());
rv.setAdapter(adapter);
return rootView;
}
private void setupData(List<List_Data> list_data) {
adapter=new MyAdapter(list_data,getContext());
rv.setAdapter(adapter);
}
}
List_Data.java:
public class List_Data {
String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
MyAdapter.java:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<List_Data>list_data;
private Context context;
private String title1;
public MyAdapter(List<List_Data> list_data, Context context) {
this.list_data = list_data;
this.context = context;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_account,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
List_Data listData=list_data.get(position);
// title1=list_data.get(0).getTitle();
holder.title.setText(listData.getTitle());
}
#Override
public int getItemCount() {
return list_data.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView img;
TextView title,subtile;
public ViewHolder(View itemView) {
super(itemView);
title=(TextView)itemView.findViewById(R.id.headingText);
subtile=(TextView)itemView.findViewById(R.id.subHeaderText);
title.setText(title1);
}
}
}
the code you have written is somehow incomplete, first you can not view any data because there are no data in the List list_data in the AccountFragment so the adapter is does not know where to fetch data from.
When you have data in the list then you can populate to the adapter.
I recommend you follow the best approach from the link below in case you have any problem please do let us know.
https://www.androidhive.info/2017/12/android-working-with-bottom-navigation/
And try your best to start using AndroidX in your project

How to fix my LinearLayout to scroll down when content exceeds view

I am adding views to my adapter dynamically and when the views exceeds the screen boundaries I am unable to see the full views.
I have tried android:isScrollContainer="true" and android:scrollbars="vertical" without any luck.
public void onAddField(View v) {
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
spin = rowView.findViewById(R.id.type_spinner2);
weightLayout = rowView.findViewById(R.id.myLayout);
getdata();
spin.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, arrayList2));
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#E5E5E5"
android:orientation="vertical"
android:scrollbars="vertical"
android:isScrollContainer="true">
Try to use this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="50dp"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>
This way your ScrollView will expand with your LinerLayout.

Android Fragment transaction from list's element

I have an ArrayAdapter MealAdapter and list's element meal_item, there are a few textviews and FrameLayout. I want to put fragment MealDetails in this FrameLayout by click on imageview. MealAdapter isn't used in Activity but in another fragment.
My item is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--icon-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/meal_number_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="6dp"
android:src="#drawable/ic_menu_gallery"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!--name-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/protein_source_name"
android:text="sdfsdfsdf"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fat_source_name"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/carb_source_name"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vegetable_source_name"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/protein_source_weight"
android:text="sdfsdfsdf"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fat_source_weight"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/carb_source_weight"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vegetable_source_weight"
android:textSize="15sp"
android:textStyle="bold"
android:text="sdfsdfsdf"/>
</LinearLayout>
</LinearLayout>
<!-- refreshMeal -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/meal_accept_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:padding="6dp"
android:src="#drawable/ic_menu_gallery"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<!--info-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/info_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/meal_details_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_menu_gallery"
android:layout_centerInParent="true"
android:tint="#8a000000"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/meal_frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginRight="4dp">
</FrameLayout>
</LinearLayout>
and adapter:
public class MealAdapter extends ArrayAdapter {
List list = new ArrayList();
private Context context;
public MealAdapter(Context context, int resource) {
super(context, resource);
this.context = context;
}
public static class DataHandler{
ImageView numberIcon;
ImageView detailsIcon;
ImageView acceptIcon;
TextView proteinSourceName;
TextView fatSourceName;
TextView carbSourceName;
TextView vegetableSourceName;
TextView proteinSourceWeight;
TextView fatSourceWeight;
TextView carbSourceWeight;
TextView vegetableSourceWeight;
FrameLayout detailsLayout;
}
#Override
public void add(Object object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return this.list.size();
}
#Override
public Object getItem(int position) {
return this.list.get(position);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final DataHandler dataHandler;
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.meal_item,parent,false);
dataHandler = new DataHandler();
dataHandler.numberIcon = (ImageView) view.findViewById(R.id.meal_number_icon);
dataHandler.detailsIcon = (ImageView) view.findViewById(R.id.meal_details_icon);
dataHandler.acceptIcon = (ImageView) view.findViewById(R.id.meal_accept_icon);
dataHandler.proteinSourceName =(TextView) view.findViewById(R.id.protein_source_name);
dataHandler.fatSourceName =(TextView) view.findViewById(R.id.fat_source_name);
dataHandler.carbSourceName =(TextView) view.findViewById(R.id.carb_source_name);
dataHandler.vegetableSourceName =(TextView) view.findViewById(R.id.vegetable_source_name);
dataHandler.proteinSourceWeight =(TextView) view.findViewById(R.id.protein_source_weight);
dataHandler.fatSourceWeight =(TextView) view.findViewById(R.id.fat_source_weight);
dataHandler.carbSourceWeight =(TextView) view.findViewById(R.id.carb_source_weight);
dataHandler.vegetableSourceWeight =(TextView) view.findViewById(R.id.vegetable_source_weight);
dataHandler.detailsLayout=(FrameLayout)view.findViewById(R.id.meal_frameLayout);
view.setTag(dataHandler);
}
else{
dataHandler=(DataHandler) view.getTag();
}
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final MealDataProvider mealDataProvider;
mealDataProvider = (MealDataProvider) this.getItem(position);
dataHandler.numberIcon.setImageResource(mealDataProvider.getNumberIcon());
dataHandler.detailsIcon.setImageResource(mealDataProvider.getShowIcon());
dataHandler.acceptIcon.setImageResource(mealDataProvider.getAcceptIcon());
dataHandler.proteinSourceName.setText(mealDataProvider.getProteinSourceName());
dataHandler.fatSourceName.setText(mealDataProvider.getFatSourceName());
dataHandler.carbSourceName.setText(mealDataProvider.getCarbSourceName());
dataHandler.vegetableSourceName.setText(mealDataProvider.getVegetableSourceName());
dataHandler.proteinSourceWeight.setText(mealDataProvider.getProteinSourceWeight());
dataHandler.fatSourceWeight.setText(mealDataProvider.getFatSourceWeight());
dataHandler.carbSourceWeight.setText(mealDataProvider.getCarbSourceWeight());
dataHandler.vegetableSourceWeight.setText(mealDataProvider.getVegetableSourceWeight());
dataHandler.detailsIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(),"click",Toast.LENGTH_LONG).show();
MealDetails mealDetails = new MealDetails();
FragmentTransaction ft = ((FragmentActivity)context).getSupportFragmentManager().beginTransaction();
ft.replace(dataHandler.detailsLayout.getId(),mealDetails);
}
});
return view;
}
}
onClick method works (there is "click" toast) but nothing else happens, the is nothing in AndroidMonitor if I click dataHandler.detailsIcon.
How is it possible to put fragment in framelayout in list's element?
Edit
I forgot about commit(), so now it works but only for FrameLayout from first list's element. It doesn't matter which list's element I click, fragment MealDetails is always place in the same FrameLayout.
Probably because every FrameLayout have the same id(?) is there any way to solve it?
You have forgotten to commit() your FragmentTransaction.
If you don't commit it, nothing will happen. Android Studio should be warning about this as well.

Android Listview is not scrolling still not working

Good day!
I have tried a lot of other posts on stackoverflow but it didn't work for me,
maybe its because I'm new to Android Development.
My problem is as follow:
XML Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="match_parent"
android:layout_height="89dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:padding="5dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="369dp"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
Preview in Android Studio:
inside the onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { }
Binding the listview:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
List<Events> list = Events.getEvents();
int max = list.size();
String[] Values = new String[max];
for (int i = 0; i < max; i++) {
Events e = list.get(i);
Values[i] = e.getNaam();
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
rootView.getContext(),
android.R.layout.simple_list_item_1, Values);
listView.setAdapter(arrayAdapter);
return rootview;
}
Another point is i can't click a list item wich is strange !
Any ideas or tips?
what do i wrong?
Kind Regards,
Stefan
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:padding="5dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
Try something like the following.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
<LinearLayout>
<ScrollView>
<ListView ...>
</listView>
</ScrollView>
</LinearLayout>
You need to add a LinearLayout around the scrollview, that way the scrollview knows inside what it should scroll. If this doesn't work, replace the ListView with another LinearLayout and add your items to the LinearLayout. I'm not sure if a View is capable of scrolling at all. Try first option first, otherwise try the latter. I know the latter will work for sure since I used the exact same design myself in an app I'm developing.
As already mentioned in the comment, you have to add a ScrollView around your ListView, e.g.:
<ScrollView>
<ListView ....>
</ListView>
</ScrollView>

Categories