Skip to content

Commit 6be420d

Browse files
Fixed click-ability & focusability of nested children of BottomSheetListView.java class and other minor fixes.
1 parent 26aaea1 commit 6be420d

8 files changed

Lines changed: 67 additions & 35 deletions

File tree

BottomSheetMenu/src/main/java/com/buggysofts/bottomsheetmenu/BottomSheetListView.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public BottomSheetListView(Context context, AttributeSet attrs, int defStyle) {
2020
super(context, attrs, defStyle);
2121
}
2222

23-
@Override
24-
public boolean onInterceptTouchEvent(MotionEvent ev) {
25-
return true;
26-
}
27-
2823
@Override
2924
public boolean onTouchEvent(MotionEvent ev) {
3025
if (canScrollVertically(this)) {

BottomSheetMenu/src/main/java/com/buggysofts/bottomsheetmenu/BottomSheetMenu.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import android.view.Menu;
1010
import android.view.MenuItem;
1111
import android.view.View;
12+
import android.view.ViewGroup;
1213
import android.widget.AdapterView;
13-
import android.widget.FrameLayout;
1414
import android.widget.LinearLayout;
1515
import android.widget.ListView;
1616
import android.widget.TextView;
@@ -35,11 +35,10 @@ public class BottomSheetMenu {
3535
// menu to be shown
3636
private final Menu mainMenu;
3737
// main root view, menu list view
38-
private final View mainView;
39-
private final FrameLayout bottomSheetContentRoot;
40-
private final ListView menuList;
41-
private final View headerView;
42-
private final View footerView;
38+
private final ViewGroup mainView;
39+
private final BottomSheetListView menuList;
40+
private final ViewGroup headerView;
41+
private final ViewGroup footerView;
4342
private final TextView titleView;
4443
private final LinearLayout customHeaderHolder;
4544
private final LinearLayout customFooterHolder;
@@ -223,30 +222,33 @@ public BottomSheetMenu(@NonNull Context context,
223222
LayoutInflater inflater = LayoutInflater.from(context);
224223

225224
// initialize class field views
226-
mainView = inflater.inflate(
225+
mainView = (ViewGroup) inflater.inflate(
227226
R.layout.bottom_sheet_menu_layout,
228-
null
229-
);
230-
headerView = inflater.inflate(
231-
R.layout.menu_header_view,
232-
null
233-
);
234-
footerView = inflater.inflate(
235-
R.layout.menu_footer_view,
236-
null
237-
);
238-
bottomSheetContentRoot = mainView.findViewById(
239-
R.id.bottom_sheet_content_root
227+
null,
228+
false
240229
);
230+
241231
menuList = mainView.findViewById(
242232
R.id.menu_list
243233
);
234+
235+
headerView = (ViewGroup) inflater.inflate(
236+
R.layout.menu_header_view,
237+
menuList,
238+
false
239+
);
244240
titleView = headerView.findViewById(
245241
R.id.menu_title
246242
);
247243
customHeaderHolder = headerView.findViewById(
248244
R.id.custom_header_holder
249245
);
246+
247+
footerView = (ViewGroup) inflater.inflate(
248+
R.layout.menu_footer_view,
249+
menuList,
250+
false
251+
);
250252
customFooterHolder = footerView.findViewById(
251253
R.id.custom_footer_holder
252254
);
@@ -291,18 +293,23 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
291293
/////////////////////////
292294

293295
private void applyProperties() {
294-
// add header and footer views in the list view
296+
// set item to be focusable
297+
menuList.setItemsCanFocus(true);
298+
299+
// set header and footer dividers if any divider is specified
295300
menuList.setHeaderDividersEnabled(dividerDrawable != null);
296301
menuList.setFooterDividersEnabled(dividerDrawable != null);
302+
303+
// add header and footer views in the list view
297304
menuList.addHeaderView(
298305
headerView,
299306
null,
300-
dividerDrawable != null
307+
true
301308
);
302309
menuList.addFooterView(
303310
footerView,
304311
null,
305-
dividerDrawable != null
312+
true
306313
);
307314

308315
// set initial properties to the views

BottomSheetMenu/src/main/java/com/buggysofts/bottomsheetmenu/BottomSheetMenuAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
9292
if (convertView == null) {
9393
convertView = LayoutInflater.from(getContext()).inflate(
9494
R.layout.menu_item_node,
95-
null
95+
parent,
96+
false
9697
);
9798
holder = new ViewHolder(
9899
convertView.findViewById(R.id.item_txt),

BottomSheetMenu/src/main/res/layout/menu_footer_view.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="wrap_content">
5+
android:layout_height="wrap_content"
6+
android:descendantFocusability="blocksDescendants">
67

78
<LinearLayout
89
android:id="@+id/custom_footer_holder"

BottomSheetMenu/src/main/res/layout/menu_header_view.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="wrap_content">
5+
android:layout_height="wrap_content"
6+
android:descendantFocusability="blocksDescendants">
67

78
<LinearLayout
89
android:id="@+id/custom_header_holder"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Finally, add this dependency to your app/module level build.gradle file
3434
3535
dependencies {
3636
...
37-
implementation 'com.github.buggysofts-com:BottomSheetMenu:v1.0.7'
37+
implementation 'com.github.buggysofts-com:BottomSheetMenu:v1.0.8'
3838
}
3939
```
4040
And you are done importing the library.

app/src/main/java/com/buggysofts/bottomsheetmenuimpl/MainActivity.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.view.MenuItem;
66
import android.view.View;
77
import android.widget.Button;
8+
import android.widget.ImageView;
9+
import android.widget.TextView;
810
import android.widget.Toast;
911

1012
import androidx.annotation.Nullable;
@@ -88,7 +90,26 @@ public void onClick(MenuItem item) {
8890
@Nullable
8991
@Override
9092
public View getInitialView() {
91-
return getLayoutInflater().inflate(R.layout.sample_header, null);
93+
View inflate = getLayoutInflater().inflate(R.layout.sample_header, null);
94+
ImageView imageView = inflate.findViewById(R.id.imageView);
95+
TextView textView = inflate.findViewById(R.id.textView);
96+
imageView.setOnClickListener(
97+
new View.OnClickListener() {
98+
@Override
99+
public void onClick(View v) {
100+
Toast.makeText(MainActivity.this, "Hi from head!", Toast.LENGTH_SHORT).show();
101+
}
102+
}
103+
);
104+
textView.setOnClickListener(
105+
new View.OnClickListener() {
106+
@Override
107+
public void onClick(View v) {
108+
Toast.makeText(MainActivity.this, "Hi from body!", Toast.LENGTH_SHORT).show();
109+
}
110+
}
111+
);
112+
return inflate;
92113
}
93114

94115
@Nullable

app/src/main/res/layout/sample_header.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@
1111
android:layout_marginTop="16dp"
1212
android:src="@drawable/ic_android"
1313
app:tint="#1aa260"
14+
android:clickable="true"
15+
android:focusable="true"
16+
android:background="?android:attr/selectableItemBackgroundBorderless"
1417
app:layout_constraintEnd_toEndOf="parent"
1518
app:layout_constraintStart_toStartOf="parent"
1619
app:layout_constraintTop_toTopOf="parent" />
1720

1821
<TextView
19-
android:id="@+id/textView2"
22+
android:id="@+id/textView"
2023
android:layout_width="wrap_content"
2124
android:layout_height="wrap_content"
2225
android:layout_marginStart="16dp"
2326
android:layout_marginEnd="16dp"
2427
android:text="Header View"
2528
android:textColor="#000000"
2629
android:textStyle="bold"
30+
android:clickable="true"
31+
android:focusable="true"
32+
android:background="?android:attr/selectableItemBackgroundBorderless"
2733
app:layout_constraintEnd_toEndOf="parent"
2834
app:layout_constraintStart_toStartOf="parent"
2935
app:layout_constraintTop_toBottomOf="@+id/imageView" />
3036

3137
<TextView
32-
android:id="@+id/textView"
38+
android:id="@+id/textView2"
3339
android:layout_width="0dp"
3440
android:layout_height="wrap_content"
3541
android:layout_marginStart="16dp"
@@ -41,5 +47,5 @@
4147
app:layout_constraintBottom_toBottomOf="parent"
4248
app:layout_constraintEnd_toEndOf="parent"
4349
app:layout_constraintStart_toStartOf="parent"
44-
app:layout_constraintTop_toBottomOf="@+id/textView2" />
50+
app:layout_constraintTop_toBottomOf="@+id/textView" />
4551
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)