Expandable ListView inside a RecyclerListView in Android - android

How to place an Expandable ListView inside a RecyclerView ListView how to do this?
Like this
without Expanding ExpandingListView
with expanding Expanding ExpandableListView
used Expandable Listview inside RecyclerView.
all are working fine but while expanding we cannot view the child items when given height as wrap content in Recycler view item height.
to view the same given a fixed height for Recyclerview item height, but it is not efficient.
any other method to do this?
Thanks in advance
Main RecyclerView Adapter
public class MySnatchitsListAdapterNew extends RecyclerView.Adapter<MySnatchitsListAdapterNew.SnatchitViewHolder> {
Context context;
ArrayList<Promotion> snatchitslist = new ArrayList<>();
LayoutInflater inflater;
AdapterInterface adapterInterface;
boolean isworkinginbackground = false;
SimpleTooltip tooltip;
public void setIsworkinginbackground(boolean isworkinginbackground) {
this.isworkinginbackground = isworkinginbackground;
}
public MySnatchitsListAdapterNew(Context context, ArrayList<Promotion> snatchitslist, AdapterInterface adapterinterface) {
this.context = context;
this.snatchitslist = snatchitslist;
this.inflater = LayoutInflater.from(context);
this.adapterInterface = adapterinterface;
}
#Override
public SnatchitViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.my_snatchit_list_item_new, null, false);
return new SnatchitViewHolder(view);
}
#Override
public void onBindViewHolder(final SnatchitViewHolder holder, int position) {
Promotion item = snatchitslist.get(position);
CommonUtils.loadProductImage(context, item.getPromotionImage(), R.drawable.no_product_image, R.drawable.no_product_image, holder.img_product);
holder.swtch_continue.setOnCheckedChangeListener(null);
holder.swtch_continue.setChecked((item.getIsDiscontinued() == 0));
holder.txt_view_count.setText(item.getViewcount() + "");
holder.txt_purchase_count.setText(item.getPurchasecount() + "");
holder.adapter = new ProductExpandableListAdapter(context,snatchitslist.get(position));
holder.exp_products.setAdapter(holder.adapter);
if (item.isdiscontinueinprogress()) {
holder.pb_discontinue.setVisibility(View.VISIBLE);
holder.swtch_continue.setVisibility(View.INVISIBLE);
} else {
holder.pb_discontinue.setVisibility(View.INVISIBLE);
holder.swtch_continue.setVisibility(View.VISIBLE);
holder.swtch_continue.setTag(position);
if (item.isdeleting() || (isworkinginbackground)) {
holder.swtch_continue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
buttonView.setChecked(!isChecked);
CommonUtils.showToast(context, context.getString(R.string.operation_in_progress));
}
});
} else {
holder.swtch_continue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int pos = (int) buttonView.getTag();
adapterInterface.doAction(MySnatchitsFragment.DISCONTINUE_PROMOTION, pos, isChecked);
}
});
}
}
holder.llyt_my_snatchit.setTag(position);
holder.llyt_my_snatchit.setTag(R.id.key_holder, holder);
holder.llyt_my_snatchit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!isworkinginbackground) {
int pos = (int) v.getTag();
SnatchitViewHolder holder = (SnatchitViewHolder) v.getTag(R.id.key_holder);
getQRCodeDetails(holder, pos);
} else {
CommonUtils.showToast(context, context.getString(R.string.operation_in_progress));
}
}
});
holder.btn_post.setTag(position);
holder.btn_post.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int pos = (int) v.getTag();
Promotion item = snatchitslist.get(pos);
if ((isworkinginbackground) || (item.isdeleting()) || (item.isdiscontinueinprogress())) {
CommonUtils.showToast(context, context.getString(R.string.operation_in_progress));
} else {
adapterInterface.doAction(MySnatchitsFragment.POST_PROMOTION, pos);
}
}
});
public void hideToolTip() {
if ((tooltip != null) && (tooltip.isShowing())) {
tooltip.dismiss();
}
}
public boolean istooltipshowing() {
boolean isshowing = false;
if ((tooltip != null) && (tooltip.isShowing())) {
isshowing = true;
}
return isshowing;
}
public class SnatchitViewHolder extends RecyclerView.ViewHolder {
ImageView img_product;
Switch swtch_continue;
Button btn_post;
LinearLayout llyt_my_snatchit;
ProgressBar pb_discontinue;
TextView txt_view_count, txt_purchase_count;
ImageView img_view_count, img_purchase_count;
ExpandableListView exp_products;
ProductExpandableListAdapter adapter ;
public SnatchitViewHolder(View itemView) {
super(itemView);
img_product = (ImageView) itemView.findViewById(R.id.img_product);
swtch_continue = (Switch) itemView.findViewById(R.id.swtch_continue);
btn_post = (Button) itemView.findViewById(R.id.btn_post);
llyt_my_snatchit = (LinearLayout) itemView.findViewById(R.id.llyt_my_snatchit);
pb_discontinue = (ProgressBar) itemView.findViewById(R.id.pb_discontinue);
txt_view_count = itemView.findViewById(R.id.txt_view_count);
txt_purchase_count = itemView.findViewById(R.id.txt_purchase_count);
img_view_count = itemView.findViewById(R.id.img_view_count);
img_purchase_count = itemView.findViewById(R.id.img_purchase_count);
exp_products = itemView.findViewById(R.id.exp_products);
}
}
}
layout - my_snatchit_list_item_new
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.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="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:animateLayoutChanges="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llyt_my_snatchit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="horizontal"
android:padding="8dp">
<ImageView
android:id="#+id/img_product"
android:layout_width="#dimen/product_image_width"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/no_product_image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/exp_products"
android:layout_width="match_parent"
android:groupIndicator="#null"
android:layout_height="wrap_content">
</ExpandableListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginTop="4dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_view_count"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/camera" />
<com.integral.app.snatchit.ui.FontTextView
android:id="#+id/txt_view_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:textColor="#color/form_text_color"
android:textAppearance="#style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_purchase_count"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/bag" />
<com.integral.app.snatchit.ui.FontTextView
android:id="#+id/txt_purchase_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:textColor="#color/form_text_color"
android:textAppearance="#style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
</LinearLayout>
<com.integral.app.snatchit.ui.FontButton
android:id="#+id/btn_post"
android:layout_width="wrap_content"
android:layout_height="#dimen/button_height_small"
android:background="#drawable/post_background"
android:elevation="2dp"
android:minWidth="0dp"
android:paddingBottom="4dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="4dp"
android:text="#string/post"
android:textColor="#color/clickable_white_text_color" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:visibility="gone"
android:animateLayoutChanges="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:animateLayoutChanges="true"
>
<Switch
android:id="#+id/swtch_continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:checked="false"
android:gravity="center_vertical"
android:textOff="no"
android:textOn="yes"
android:thumb="#drawable/swith_thumb"
android:track="#drawable/swith_track"
android:visibility="visible" />
</LinearLayout>
<ProgressBar
android:id="#+id/pb_discontinue"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:animateLayoutChanges="true"
android:padding="2dp"
android:visibility="invisible" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Inner Expandable ListView Adapter - ProductExpandableListAdapter
package com.integral.app.snatchit.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.integral.app.snatchit.R;
import com.integral.app.snatchit.model.Product;
import com.integral.app.snatchit.model.Promotion;
import com.integral.app.snatchit.util.CommonUtils;
/**
* Created by sanoop on 23-01-2018.
*/
public class ProductExpandableListAdapter extends BaseExpandableListAdapter {
Context context;
Promotion promotion;
public ProductExpandableListAdapter(Context context, Promotion promotion) {
this.context = context;
this.promotion = promotion;
}
#Override
public int getGroupCount() {
return 1;
}
#Override
public int getChildrenCount(int groupPosition) {
int childcount = (promotion.getProducts().size() - 2);
return (childcount<0)? 0 : childcount;
}
#Override
public Object getGroup(int groupPosition) {
return promotion;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return promotion.getProducts().get(childPosition + 2);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.my_snatchit_product_item_header, null, false);
ProductHeaderViewHolder holder = new ProductHeaderViewHolder(convertView);
convertView.setTag(holder);
}
ProductHeaderViewHolder holder = (ProductHeaderViewHolder) convertView.getTag();
if (promotion.getProducts().size() > 0) {
Product firstproduct = promotion.getProducts().get(0);
holder.txt_product_name_1.setText(firstproduct.getProductName());
String currencysymbol = CommonUtils.getCurrencySymbol(promotion.getCurrencyCode());
holder.txt_local_price_1.setText(currencysymbol + firstproduct.getProductPriceLocal());
holder.txt_international_price_1.setText(currencysymbol + firstproduct.getProductPriceInternational());
}
if (promotion.getProducts().size() > 1) {
holder.llyt_product_2.setVisibility(View.VISIBLE);
Product firstproduct = promotion.getProducts().get(1);
holder.txt_product_name_2.setText(firstproduct.getProductName());
String currencysymbol = CommonUtils.getCurrencySymbol(promotion.getCurrencyCode());
holder.txt_local_price_2.setText(currencysymbol + firstproduct.getProductPriceLocal());
holder.txt_international_price_2.setText(currencysymbol + firstproduct.getProductPriceInternational());
} else {
holder.llyt_product_2.setVisibility(View.GONE);
}
if (promotion.getProducts().size() > 2) {
holder.img_show_more.setVisibility(View.VISIBLE);
holder.img_show_more.setImageResource(isExpanded ? R.drawable.drop_up : R.drawable.drop_down);
} else {
holder.img_show_more.setVisibility(View.GONE);
}
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.my_snatchit_product_item_child, null, false);
ProductChildViewHolder holder = new ProductChildViewHolder(convertView);
convertView.setTag(holder);
}
ProductChildViewHolder holder = (ProductChildViewHolder) convertView.getTag();
Product childproduct = promotion.getProducts().get(childPosition+2);
holder.txt_product_name.setText(childproduct.getProductName());
String currencysymbol = CommonUtils.getCurrencySymbol(promotion.getCurrencyCode());
holder.txt_local_price.setText(currencysymbol + childproduct.getProductPriceLocal());
holder.txt_international_price.setText(currencysymbol + childproduct.getProductPriceInternational());
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
public class ProductHeaderViewHolder {
TextView txt_product_name_1, txt_local_price_1, txt_international_price_1, txt_product_name_2, txt_local_price_2, txt_international_price_2;
FrameLayout flyt_remove;
ProgressBar pb_remove;
LinearLayout llyt_product_2;
ImageView img_show_more;
public ProductHeaderViewHolder(View itemview) {
txt_product_name_1 = itemview.findViewById(R.id.txt_product_name_1);
txt_product_name_2 = itemview.findViewById(R.id.txt_product_name_2);
txt_local_price_1 = itemview.findViewById(R.id.txt_local_price_1);
txt_local_price_2 = itemview.findViewById(R.id.txt_local_price_2);
txt_international_price_1 = itemview.findViewById(R.id.txt_international_price_1);
txt_international_price_2 = itemview.findViewById(R.id.txt_international_price_2);
flyt_remove = itemview.findViewById(R.id.flyt_remove);
pb_remove = itemview.findViewById(R.id.pb_remove);
llyt_product_2 = itemview.findViewById(R.id.llyt_product_2);
img_show_more = itemview.findViewById(R.id.img_show_more);
}
}
public class ProductChildViewHolder {
TextView txt_product_name, txt_local_price, txt_international_price;
public ProductChildViewHolder(View itemview) {
txt_product_name = itemview.findViewById(R.id.txt_product_name);
txt_local_price = itemview.findViewById(R.id.txt_local_price);
txt_international_price = itemview.findViewById(R.id.txt_international_price);
}
}
}
ExpandableListAdapter view not able to include because of body size limitaion.
but it is simple textviews not much complicated ones.

compile 'net.cachapa.expandablelayout:expandablelayout:2.9.1' use this library for expandable layout.

Related

Float items below ExpandableListview

Before expand
After expand
İf height match_parent override other views
I WANT TO GET LİKE THİS EXPAND AND CLOSE
I WANT TO GET LİKE THİS EXPAND AND CLOSE OTHER EXPANDABLE LİST VİEWS
It is my xml file for showing expandable list etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginBottom="50dp"
android:layout_marginLeft="180dp"
android:background="#drawable/sizeozel_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="SİZE ÖZEL"
android:textSize="24sp"
android:layout_marginTop="55dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="95dp"
/>
<ExpandableListView
android:id="#+id/exp_referans_linkim"
android:layout_width="match_parent"
android:layout_height="49dp"
android:layout_marginTop="105dp"
android:layout_weight="1"
></ExpandableListView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="165dp"
/>
<ExpandableListView
android:id="#+id/exp_satislarim"
android:layout_width="match_parent"
android:layout_height="49dp"
android:layout_marginTop="175dp"
android:layout_weight="1"
></ExpandableListView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="235dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginTop="245dp"
android:text="İş Ortaklarım"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="270dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginTop="280dp"
android:text="Sepetim"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="305dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginTop="315dp"
android:text="Alınan Ürünler"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="340dp"
/>
<ExpandableListView
android:id="#+id/exp_bilgilerim"
android:layout_width="match_parent"
android:layout_height="49dp"
android:layout_marginTop="355dp"
android:layout_weight="1"
></ExpandableListView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#drawable/size_ozel_divider"
android:layout_marginTop="420dp"
/>
</RelativeLayout>
My adapter java file for expandable list view
package arabulkazan.albatros.com.arabulkazan.Adapters;
import android.content.Context;
import android.database.DataSetObserver;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
import arabulkazan.albatros.com.arabulkazan.MainActivity;
import arabulkazan.albatros.com.arabulkazan.R;
import static arabulkazan.albatros.com.arabulkazan.Fragments.SizeOzel.ref_childListMap;
import static arabulkazan.albatros.com.arabulkazan.Fragments.SizeOzel.ref_groupList;
public class Exp_Ref_List_Adapter implements ExpandableListAdapter {
Context context;
public Exp_Ref_List_Adapter(Context context) {
this.context = context;
}
#Override
public void registerDataSetObserver(DataSetObserver dataSetObserver) {
}
#Override
public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
}
#Override
public int getGroupCount() {
return ref_groupList.size();
}
#Override
public int getChildrenCount(int groupIndex) {
String group = ref_groupList.get(groupIndex);
List<String> childInfoList = ref_childListMap.get(group);
return childInfoList.size();
}
#Override
public Object getGroup(int groupIndex) {
return ref_groupList.get(groupIndex);
}
#Override
public Object getChild(int groupIndex, int childIndex) {
String group = ref_groupList.get(groupIndex);
List<String> childInfoList = ref_childListMap.get(group);
return childInfoList.get(childIndex);
}
#Override
public long getGroupId(int groupIndex) {
return groupIndex;
}
#Override
public long getChildId(int groupIndex, int childIndex) {
return childIndex;
}
#Override
public boolean hasStableIds() {
return true;
}
// This method will return a View object displayed in group list item.
#Override
public View getGroupView(int groupIndex, boolean isExpanded, View view, ViewGroup viewGroup) {
// Create the group view object.
LinearLayout groupLayoutView = new LinearLayout(context);
groupLayoutView.setOrientation(LinearLayout.HORIZONTAL);
// Create and add a textview in returned group view.
String groupText = ref_groupList.get(groupIndex);
TextView groupTextView = new TextView(context);
groupTextView.setText(groupText);
groupTextView.setTextSize(30);
groupLayoutView.addView(groupTextView);
return groupLayoutView;
}
// This method will return a View object displayed in child list item.
#Override
public View getChildView(int groupIndex, int childIndex, boolean isLastChild, View view, ViewGroup viewGroup) {
// First get child text/
Object childObj = this.getChild(groupIndex, childIndex);
String childText = (String)childObj;
// Create a TextView to display child text.
TextView childTextView = new TextView(context);
childTextView.setText(childText);
childTextView.setTextSize(20);
// childTextView.setBackgroundColor(Color.GREEN);
// Set child textview offset left. Then it will align to the right of the group image.
childTextView.setPadding(15,0,0,0);
return childTextView;
}
#Override
public boolean isChildSelectable(int groupIndex, int childIndex) {
return false;
}
#Override
public boolean areAllItemsEnabled() {
return false;
}
#Override
public boolean isEmpty() {
return false;
}
#Override
public void onGroupExpanded(int groupIndex) {
}
#Override
public void onGroupCollapsed(int groupIndex) {
}
#Override
public long getCombinedChildId(long groupIndex, long childIndex) {
return 0;
}
#Override
public long getCombinedGroupId(long groupIndex) {
return 0;
}
}
And my main fragment java code
public class Main extends android.support.v4.app.Fragment {
public static List<String> ref_groupList = null;
public static Map<String, List<String>> ref_childListMap = null;
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View root=inflater.inflate(R.layout.fragment_main_page, container, false);
this.referans_linkim("Referans Linkim","12345678","kobi45678");
Exp_Ref_List_Adapter exp_ref_list_adapter=new Exp_Ref_List_Adapter(SizeOzel.this.getActivity());
final ExpandableListView exp_ref = (ExpandableListView)root.findViewById(R.id.exp_referans_linkim);
DisplayMetrics metrics = new DisplayMetrics();//for determine indicator position
SizeOzel.this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
final float scale = getResources().getDisplayMetrics().density;
int elli= (int) (50 * scale + 0.5f);
int on= (int) (10 * scale + 0.5f);
exp_ref.setIndicatorBounds(width-elli,width-on);
exp_ref.setAdapter(exp_ref_list_adapter);
// Add on group expand listener.
exp_ref.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupIndex) {
// Get total group size.
int groupListSize = ref_groupList.size();
// Close other expanded group.
for(int i=0;i < groupListSize; i++) {
if(i!=groupIndex) {
exp_ref.collapseGroup(i);
}
}
}
});
// Referansım linkim data assign
private void referans_linkim(String name,String temsil_kod,String kobi_kod)
{
if(this.ref_groupList == null)
{
this.ref_groupList = new ArrayList<String>();
}
if(this.ref_childListMap == null)
{
this.ref_childListMap = new HashMap<String, List<String>>();
}
if(!this.ref_groupList.contains(name)) {
this.ref_groupList.add(name);
}
// Create child list.
List<String> childList = new ArrayList<String>();
childList.add("Temsilci Kodu: " + temsil_kod);
childList.add("Kobi Kodu: " + kobi_kod);
// Add child data list in the map, key is group name.
this.ref_childListMap.put(name, childList);
}
}
When i try to expand my expandable listview its expanded.But it compress itself to determine width and height.I want to float items that under expandable list.How can i do that? Thanks in advance

Showing or hiding an object in a listview

The image in the imageview disappears from the scrollview in the ListView. How can i solve it?
public class IzahAdapter extends BaseAdapter {
private ArrayList<IzahVeriModeli> list;
LayoutInflater layoutInflater;
Context context;
holder Holder;
int pos;
public IzahAdapter(Context context, ArrayList<IzahVeriModeli> list) {
this.context = context;
// Layout Inflater tanımlanıyor...
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder=null;
View satirView = null;
Button bIngg, bTrr;
ImageView resimm = null;
//
if (convertView == null) {
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.listview_izahat, parent, false);
Holder = new holder();
Holder.resim = (ImageView) convertView.findViewById(resim);
Holder.bIng = (Button) convertView.findViewById(bIng);
Holder.bTr = (Button) convertView.findViewById(bTr);
Holder.bTr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pos = (Integer)v.getTag();
list.get(pos).setSelected(false);
System.out.println("pip2 = " + Integer.toString(pos));
notifyDataSetChanged();
}
});
Holder.bIng.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int pos = (Integer)v.getTag();
list.get(pos).setSelected(true);
System.out.println("pip3 = " + Integer.toString(pos));
notifyDataSetChanged();
}
});
convertView.setTag(Holder);
}
else {
Holder = (holder) convertView.getTag();
}
Holder.bTr.setTag(position);
Holder.bIng.setTag(position);
Holder.resim.setTag(position);
System.out.println("pip1 = " + position);
if (list.get(position).isSelected()) {
Holder.bTr.setVisibility(View.VISIBLE);
Holder.bIng.setVisibility(View.GONE);
notifyDataSetChanged();
} else {
Holder.bTr.setVisibility(View.GONE);
Holder.bIng.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}
if (this.list.get(position).getResim()!=null)
{
Holder.resim.setImageBitmap(this.list.get(position).getResim2());
}
else
{
Holder.resim.getLayoutParams().width=0;
}
return convertView;
}
}
The image in Imageview comes from the data base. ImageView is shrinking if it is null, if not it adds image, but when i scroll the listview, things get messed up.
I did a lot of hard work, but i did not get resolved it.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#drawable/satir_arkaplan"
android:orientation="horizontal"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/resim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:baselineAligned="false"
android:gravity="center_horizontal|center"
android:orientation="vertical"
android:padding="5dp">
<Button
android:id="#+id/bIng"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ing"
android:textSize="9dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/bTr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center"
android:background="#drawable/turk"
android:textSize="10dp" />
</LinearLayout>
Try something like that:
if (this.list.get(position).getResim()!=null) {
Holder.resim.setVisibility(View.Visible);
Holder.resim.setImageBitmap(this.list.get(position).getResim2());
}
else {
Holder.resim.setVisibility(View.Gone);
Holder.resim.setImageresource(0);
}

Recycle view overlap items on scroll

Hello everyone i am facing a problem with recycle view.
im using a recycle view with swipe to change item position functionality where user can change the position of items by long press items.
all items comes dynamical with different types of views.
everything is working good but when im trying to scroll the view then items displaying in recycle view are overlap each other.
i search on google and got the solution that is override the method .
#Override
public int getItemViewType(int position) {
return position;
}
when im using this method in my adapter class then my swipe to change view functionality stop working.
can anyone explain my why it's happening..?
Here is whole adapter class
public class CreateEmailAdapter extends RecyclerView.Adapter<CreateEmailAdapter.MyViewHolder> implements ItemTouchHelperAdapter {
private static final String TAG = "CreateEmailAdapter";
public int position = 0;
public ArrayList<CampaignData> List;
private final OnStartDragListener mDragStartListener;
public CreateEmailAdapter(ArrayList<CampaignData> List, OnStartDragListener mDragStartListener) {
this.List = List;
this.mDragStartListener = mDragStartListener;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title;
public ImageView imageView, imageView2, imageView3;
RelativeLayout MainListView;
public MyViewHolder(final View view) {
super(view);
parentLayout = (RelativeLayout) view.findViewById(R.id.parentLayout);
MainListView = (RelativeLayout) view.findViewById(R.id.MainListView);
title = (TextView) view.findViewById(R.id.MainTitle);
imageView2 = (ImageView) view.findViewById(R.id.imageViewPopup);
imageView3 = (ImageView) view.findViewById(R.id.movearrows);
imageView = (ImageView) view.findViewById(R.id.lytPatternColorDraw);
parentLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view1) {
position = getAdapterPosition();
HandleResponse(title.getText().toString(), view1, getAdapterPosition());
}
});
}
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_row, parent, false);
return new MyViewHolder(mView);
}
#Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
CampaignData campaignData = this.List.get(position);
holder.parentLayout.setTag(campaignData);
String extraData = campaignData.getExtraData();
String MediaType = campaignData.getMediaType();
holder.MainListView.setVisibility(View.VISIBLE);
holder.title.setText(campaignData.getTitle());
holder.imageView.setImageResource(campaignData.getimage());
holder.imageView2.setTag(campaignData);
holder.imageView3.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragStartListener.onStartDrag(holder);
}
return false;
}
});
}
#Override
public boolean onItemMove(int fromPosition, int toPosition) {
Collections.swap(List, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
return true;
}
#Override
public void onItemDismiss(int position) {
List.remove(position);
notifyItemRemoved(position);
}
#Override
public int getItemCount() {
return List.size();
}
// #Override
// public int getItemViewType(int position) {
// return position;
// }
public int getPosition() {
return position;
}
}
XMl file list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<RelativeLayout
android:id="#+id/MainListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/lytGrab"
android:visibility="visible">
<LinearLayout
android:id="#+id/lytPatternColor"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<ImageView
android:id="#+id/movearrows"
android:layout_width="18dp"
android:layout_height="36dp"
android:layout_marginRight="10dp"
android:background="#drawable/movearrows" />
<ImageView
android:id="#+id/lytPatternColorDraw"
android:layout_width="30dp"
android:layout_height="40dp"
android:orientation="vertical" />
</LinearLayout>
<TextView
android:id="#+id/MainTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_toRightOf="#+id/lytPatternColor"
android:gravity="center_vertical"
android:padding="10dp"
android:singleLine="true"
android:text="Title Here "
android:textColor="#000"
android:textSize="16sp" />
</RelativeLayout>
<!--Copy images -->
<LinearLayout
android:id="#+id/lytGrab"
android:layout_width="30dp"
android:layout_height="70dp"
android:layout_alignParentRight="true"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/three" />
</LinearLayout>
</RelativeLayout>

layout with listview and text below

I have a text below a listview and I need that if listview contains more items, to push the text down more. Because many items in my listview, causes the view to look bad. Look at the example to understand
Picture
My code is
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Mañana"
android:id="#+id/manianaTitle" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/listaManiana"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Tarde"
android:id="#+id/tardeTitle" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/listaTarde"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Noche"
android:id="#+id/nocheTitle" />
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/listaNoche"
android:layout_gravity="center_horizontal" />
</LinearLayout>
`
It is better to use a ListView with section. In that case you can categorize each section in your ListView instead of using many ListViews and TextViews.
I found this example from this website and I did some modification in the code
Create your List Item View
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/photo"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="32dp"
android:src="#drawable/female"
android:contentDescription="#string/app_name"/>
<TextView
android:id="#+id/photo_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#+id/photo"
android:layout_alignTop="#+id/photo"/>
</RelativeLayout>
Create a layout for the header section
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:gravity="center_vertical"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FF000000" />
</LinearLayout>
Create an adapter for your List View
import java.util.ArrayList;
import java.util.TreeSet;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
class CustomAdapter extends BaseAdapter {
private static final int TYPE_ITEM = 0;
private static final int TYPE_SEPARATOR = 1;
private ArrayList<EntityObject> mData = new ArrayList<String>();
private TreeSet<Integer> sectionHeader = new TreeSet<Integer>();
private LayoutInflater mInflater;
public CustomAdapter(Context context) {
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(final EntityObject item) {
mData.add(item);
notifyDataSetChanged();
}
public void addSectionHeaderItem(final String item) {
mData.add(item);
sectionHeader.add(mData.size() - 1);
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
return sectionHeader.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public String getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (rowType) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.snippet_item1, null);
holder.textView = (TextView) convertView.findViewById(R.id.photo_details);
holder.photo = (ImageView)convertView.findViewById(R.id.photo)
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.snippet_item2, null);
holder.textView = (TextView) convertView.findViewById(R.id.textSeparator);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mData.get(position).getText());
holder.setImageResource(mData.get(position).getImage());
return convertView;
}
public static class ViewHolder {
public TextView textView;
public ImageView photo;
}
}

Make LinearLayout with TextView and ExpendableListView scrollable using CWAC-Merge

My problem is, that I have an activity with one big TextView and one ExpandableListView underneath the TextView. Unfortunately the text of the TextView is too long, so I can't see the details when I expand the ExpandableListView.
So my question is, how can I use CWAC-Merge in my Code, to get one big scrollable Activity.
I would like to have, that everything in the activity_contact.xml from scrollView1 to the bottom is scrollable! I already copied the necessary libs (merge-1.0.1.jar and sacklist-1.0.0.jar) to my Project, but I don't know how to apply the MergeAdapter. I would really appreciate, if someone could tell me where and how I have to use the MergeAdapter!
This is my activity_contact.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/titlebar" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:fillViewport="true" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/contact"
android:textSize="#dimen/textSize" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
</ExpandableListView>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
This is my Contact.java class:
public class Contact extends Activity {
private SparseArray<Group> groups = new SparseArray<Group>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact);
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
createData();
ExpandableListAdapter adapter = new ExpandableListAdapter(this, groups,
false, null);
listView.setAdapter(adapter);
}
private void createData() {
Group group1 = new Group(getString(R.string.stringGroup));
group1.children.add(getString(R.string.stringGroup2));
groups.append(0, group1);
}
}
This is my ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private final SparseArray<Group> groups;
private LayoutInflater inflater;
private Activity activity;
private boolean setOnClickListener;
private Class<?> onClickClass;
public ExpandableListAdapter(Activity act, SparseArray<Group> groups,
boolean setOnClickListener, Class<?> onClickListenerClass) {
activity = act;
this.groups = groups;
inflater = act.getLayoutInflater();
this.setOnClickListener = setOnClickListener;
this.onClickClass = onClickListenerClass;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return groups.get(groupPosition).children.get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String children = (String) getChild(groupPosition, childPosition);
TextView text = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_details, null);
}
text = (TextView) convertView.findViewById(R.id.copyrightTextView);
text.setText(Html.fromHtml(children));
if (setOnClickListener) {
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(activity, onClickClass);
intent.putExtra("name", children);
activity.startActivity(intent);
}
});
}
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return groups.get(groupPosition).children.size();
}
#Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
#Override
public int getGroupCount() {
return groups.size();
}
#Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
#Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
#Override
public long getGroupId(int groupPosition) {
return 0;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_group, null);
}
Group group = (Group) getGroup(groupPosition);
((CheckedTextView) convertView).setText(group.string);
((CheckedTextView) convertView).setChecked(isExpanded);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
The listrow_details.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/copyrightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="15dp"
android:gravity="center_vertical"
android:linksClickable="true"
android:padding="10dp"
android:textStyle="bold" >
</TextView>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/black" />
</LinearLayout>
MergeAdapter is a ListAdapter, not an ExpandableListAdapter. You cannot use MergeAdapter to solve your problem. You are welcome to read through the source code to MergeAdapter and attempt to figure out if there is a way to create a MergeExpandableListAdapter or something like that.
Or, come up with a UI that does not have a long TextView after the ExpandableListView.

Categories

Resources