I have a listview with some texts in it like this
and I want to expand each item to like this
I have seen this answer(How can I make a cell in a ListView in Android expand and contract vertically when it's touched?), here it doesn't changes to a new view, but just changes the height.
UPDATE:list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="#drawable/list_selected">
<RelativeLayout
android:id="#+id/relaboveline1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/sidebar"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="#4ED6CA" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:weightSum="100"
android:layout_toRightOf="#+id/sidebar"
android:layout_toEndOf="#+id/sidebar">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:id="#+id/cal"
android:layout_width="60dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22"
android:textColor="#FF8801"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:textSize="35sp"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/month"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/date"
android:textSize="20sp"
android:text="MAY" />
<TextView
android:id="#+id/year"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/month"
android:textSize="20sp"
android:text="2015" />
</RelativeLayout>
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/cal"
android:layout_toEndOf="#+id/cal"
android:background="#DADADA" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60">
<RelativeLayout
android:id="#+id/content"
android:layout_width="200dp"
android:paddingTop="5dp"
android:paddingLeft="8dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="High School Graduation" />
<TextView
android:id="#+id/contentdesc"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:text="#string/dummy" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="5B"
android:id="#+id/classDiv" />
<RelativeLayout
android:layout_below="#+id/classDiv"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="#drawable/star_yellow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/relaboveline1"
android:background="#DADADA" />
You can use ExpandableListView:
You define a custom layout for the child (the details when you click on the row)
You define an public class ExpandableAdapter extends BaseExpandableListAdapter
Override the method
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
....
}
where you implement your detail layout (child layout).
Override the method
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
...
}
where you implement the layout like the ListView.
Set the custom adapter in your ExpandableListView instance
If you want to have more info give a look at my post here http://www.survivingwithandroid.com/2013/01/android-expandablelistview-baseexpandablelistadapter.html
Have you tried ExpandableListView with only one child view for each group view? then you can expand and collapse rows as you want.
Related
I have a custom listview, inside of which there is another one. And the one that is nested will not scroll. Perhaps you need to register something in the parent setOnTouchListener? I don't have anything like that in getView.
image
my layout
<?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/gray"
tools:context=".invoice.ListPruducts">
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp"
android:paddingHorizontal="10dp"
android:paddingVertical="10dp"
android:stackFromBottom="true"
app:layout_constraintBottom_toTopOf="#+id/materialCardView2"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="10dp" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView2"
android:background="#color/zxing_transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomCardViewStyle"
android:layout_marginTop="10dp"
app:cardElevation="10dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/productName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:backgroundTint="#color/yellow"
android:enabled="false"
android:hint="Наименование"
android:textColor="#color/black"
android:textColorHint="#color/black"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/ll123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/productName"
android:layout_marginHorizontal="5dp"
android:layout_marginTop="5dp"
android:baselineAligned="false"
android:orientation="horizontal">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/search_barCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#color/green"
android:ems="15"
android:focusable="true"
android:hint="Считайте ш/к"
android:textColorHint="#color/DefGray"
android:inputType="number"
android:maxLength="15"
android:textSize="18sp"
android:singleLine="true" />
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/coutOfProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:backgroundTint="#color/green"
android:hint="Кол-во: "
android:inputType="numberSigned|numberDecimal"
android:maxLength="13"
android:singleLine="true"
android:textColor="#color/black"
android:textColorHint="#color/DefGray"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
`
my getView
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
GoodsCreate_SQL myItemFromList = getItem(position);
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(mResourse, parent, false);
TextView tvMark = convertView.findViewById(R.id.tvMark);
CheckBox cb = convertView.findViewById(R.id.checkBox2);
tvMark.setText(myItemFromList.Mark);
if (myItemFromList.myMark.equals("1")){
cb.setChecked(true);
}
return convertView;
}
Tried setOnTouchListener to write view.getParent().requestDisallowInterceptTouchEvent(true);
I have a view in an activity as below .I want to set Margin to the view.But i used Viewgroup.LayoutParams but it doesn't change the view of the row.Below i have given custom adapter which takes data from firstpagerowitems.xml.I have given the java code for adapter .I tried doing android:layout_marginbottom="10dp" for firstpagerowitems.xml and firstpage.xml but it doesnt work.
class MyAdapter extends ArrayAdapter<String> {
Context context;
ArrayList<String> rTitle;
ArrayList<String> rDescription;
ArrayList<String> rImgs;
MyAdapter (Context c, ArrayList<String> title,ArrayList<String> description,ArrayList<String> imgs) {
super(c, R.layout.firstpagerowitems, R.id.textView1, title);
this.context = c;
this.rTitle = title;
this.rDescription = description;
this.rImgs = imgs;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflater.inflate(R.layout.firstpagerowitems, parent, false);
TextView images = row.findViewById(R.id.textView3);
TextView myTitle = row.findViewById(R.id.textView1);
TextView myDescription = row.findViewById(R.id.textView2);
Log.d("entered last","yes");
Log.d("postion", String.valueOf(position));
Log.d("rimgs", String.valueOf(rImgs));
Log.d("desc", String.valueOf(rDescription));
Log.d("title", String.valueOf(rTitle));
// now set our resources on views
images.setText(rImgs.get(position));
myTitle.setText(rTitle.get(position));
myDescription.setText(rDescription.get(position));
Random random=new Random();
int trp=random.nextInt(16);
Log.d("enteredcolor",mycolors[trp]);
// images.setBackgroundResource(R.color.lightgreen);
String fd=mycolors[trp];
// images.setBackgroundColor(Color.parseColor(fd));
// LinearLayout mylinear=row.findViewById(R.id.mylinear);
// mylinear.setBackgroundColor(Color.parseColor(fd));
row.setBackgroundColor(Color.parseColor(fd));
// ViewGroup.MarginLayoutParams margins=new ViewGroup.MarginLayoutParams(row.getLayoutParams());
// margins.setMargins(0,100,0,100);
// ViewGroup.LayoutParams layouts=new ViewGroup.LayoutParams(margins);
// row.setLayoutParams(layouts);
// ViewGroup.LayoutParams params=new ViewGroup.LayoutParams(row);
return row;
}
}
code.java
<?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="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="one"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="20sp"
android:layout_weight="0.2"
android:id="#+id/textView1"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="two"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="20sp"
android:layout_weight="0.45"
android:id="#+id/textView2"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="three"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:layout_margin="5dp"
android:textSize="20sp"
android:layout_weight="0.35"
android:id="#+id/textView3"
/>
</LinearLayout>
firsypagerowitems.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
tools:context=".Firstpage">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="#+id/mylinear">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
>
</ListView>
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/fabs"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
app:fabSize="normal"
app:backgroundTint="#color/design_default_color_error"
app:elevation="6dp"
android:src="#android:drawable/ic_input_add"
>
</com.google.android.material.floatingactionbutton.FloatingActionButton>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
firstpage.xml
Try whether this helps...
<?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="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:layout_marginBottom="5dp"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:textSize="20sp"
android:layout_weight="0.2"
android:id="#+id/textView1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:layout_marginBottom="5dp"
android:textSize="20sp"
android:layout_weight="0.45"
android:id="#+id/textView2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three"
android:textColor="#color/colorWhite"
android:textStyle="bold"
android:textSize="20sp"
android:layout_weight="0.35"
android:id="#+id/textView3"
/>
</LinearLayout>
Hope this helps. Feel free to ask for clarifications...
I have an ExpandableListView in my app. I want to make the child layout a bit narrower than the group header and also keep it centered. Due to some visual effects i must set layout params from code however i can't seem to find the best solutions for this tried changing layout width from xml with no luck. Any advice will be helpful.
Thanks
adapter getChild() method:
#Override
public View getChildView(final int groupPosition, final int
childPosition,
boolean isLastChild, View convertView,
ViewGroup parent) {
final Item expandedListitem = (Item) getChild(groupPosition, childPosition);
Drawable drawable= ContextCompat.getDrawable(context,R.drawable.background_border);
GradientDrawable gradientDrawable= (GradientDrawable) drawable;
gradientDrawable.setStroke(5,expandedListitem.getColor());
if (Build.VERSION.SDK_INT >= 19) {
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item, null);
}
if (!isLastChild) {
View divider = convertView.findViewById(R.id.linearfaq);
divider.setVisibility(View.INVISIBLE);
ViewGroup.LayoutParams params = convertView.getLayoutParams();
int width = (MainActivity.display.getWidth());
params.height = 110;
params.width=width-40;
params.addRule(RelativeLayout.CENTER_IN_PARENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
convertView.setLayoutParams(params);
View padder = convertView.findViewById(R.id.padder);
padder.setVisibility(View.INVISIBLE);
} else {
View divider = convertView.findViewById(R.id.linearfaq);
RelativeLayout.LayoutParams params = new
[![enter image description here][1]][1]RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
int width = (MainActivity.display.getWidth());
params.height = 140;
params.width=width-40;
params.addRule(RelativeLayout.CENTER_IN_PARENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
convertView.setLayoutParams(params);
divider.setVisibility(View.VISIBLE);
View padder = convertView.findViewById(R.id.padder);
padder.setBackgroundColor(expandedListitem.getColor());
padder.setVisibility(View.VISIBLE);
}
}else{
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item_low, null);
}
}
Item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/back" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
>
<CheckBox
android:layout_alignParentLeft="true"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusableInTouchMode="false"
android:layout_marginRight="8dp"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_height="wrap_content"
android:id="#+id/checkbox"
/>
<TextView
android:inputType="text"
android:paddingRight="8dp"
android:layout_width="wrap_content"
android:focusable="false"
android:layout_marginTop="6dp"
android:textSize="16sp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/checkbox"
android:layout_toEndOf="#+id/checkbox"
android:id="#+id/list_text"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/del"
android:src="#android:drawable/ic_menu_delete"
android:layout_marginTop="3dp"
android:background="#null"
android:visibility="gone"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/checkbox"
android:layout_alignBottom="#+id/checkbox"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:orientation="horizontal"
android:id="#+id/relativeLayout">
<Button
android:id="#+id/plus"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:background="#drawable/round_button"
android:clickable="true"
android:focusable="false"
android:text="+" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_toEndOf="#+id/plus"
android:layout_toRightOf="#+id/plus" />
<Button
android:id="#+id/minus"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_toEndOf="#+id/quantity"
android:layout_toRightOf="#+id/quantity"
android:background="#drawable/round_button"
android:clickable="true"
android:focusable="false"
android:text="-" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/linearfaq"
android:layout_marginTop="35dp"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/back"
android:orientation="vertical" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/padder"
android:layout_width="match_parent"
android:background="#color/blue"
android:visibility="gone"
android:layout_height="2dp"
android:layout_alignTop="#+id/linearfaq"
>
</RelativeLayout>
category layout:
<?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="horizontal"
android:background="#drawable/parent_border">
<TextView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:focusable="false"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cat_text"/>
I'd put all Views in one single ConstraintLayout. By attaching the background to the parent left and right, the View is default centered. By adding margins left and right, you achieve the View being smaller.
Like in this example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView2"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:background="#android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:buttonTint="#android:color/background_light"
android:text="CheckBox"
android:textColor="#android:color/background_light"
app:layout_constraintBottom_toBottomOf="#+id/imageView2"
app:layout_constraintStart_toStartOf="#+id/imageView2"
app:layout_constraintTop_toTopOf="#+id/imageView2" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="Stuff"
android:textColor="#android:color/background_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/checkBox"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
which looks like this:
the
android:layout_width="0dp"
actually means the view will be stretched to match the constraints. A bit like "match_parent", but within the bounds you set via its constraints.
Play around with the ConstraintLayout a bit. Once you get the hang of it, you will not want to miss it anymore :)
Why Snackbar cover my view
here is my xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fullview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_gray"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true"
android:text="#string/reload"
android:visibility="visible" />
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="#+id/complist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fadeScrollbars="false" />
</RelativeLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/send"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#color/blue"
android:text="#string/send"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#color/green"
android:text="#string/cancel"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
java code used to show snake bar
private CoordinatorLayout _CoordinatorLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.compition, null);
_CoordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.fullview);
}
Snackbar.make(_CoordinatorLayout , message , Snackbar.LENGTH_LONG).show();
here is screen shot
what I miss ??
The documentation here says:
Snackbars appear above all other elements on screen and only one can
be displayed at a time.
So, Snackbar will cover your view, just like a Toast.
There is the following code:
mListOfExistedMessages.setAdapter(new ExistedTasksExpandableListAdapter(context, persons));
mListOfExistedMessages.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent,
View v, int groupPosition, int childPosition,
long id) {
Toast.makeText(ExistedMessagesActivity.this, "1",
Toast.LENGTH_LONG).show();
return false;
}
});
mListOfExistedMessages.setItemsCanFocus(false);
ExistedTasksExpandableListAdapter is my custom adapter, and code of adapter works good (shows custom views for group and child). Code of child layout:
<?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:focusable="false"
android:orientation="horizontal"
android:padding="10dip"
android:paddingLeft="15dip" >
<CheckBox
android:id="#+id/listItemExistedMessageChecked"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:text="" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.7"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical" >
<TextView
android:id="#+id/listItemExistedMessageText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxLines="2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/listItemExistedMessageRepeating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="italic" />
</LinearLayout>
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:layout_marginLeft="5dip"
android:background="#1874CD"
android:focusable="false"
android:focusableInTouchMode="false" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Next event:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/listItemExistedMessageDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
But there is no messages by child view clicking! How can I fix it?
Try to add:
return super.onChildClick(parent, v, groupPosition, childPosition, id);
instead of false. Did this work for you?