How to set a title on BottomSheetDialog with grid?
up vote
0
down vote
favorite
I have created a BottomSheetDialog
with a GridView
, but I know that BottomSheetDialog
can't set a title using the method .setTitle()
, so how can I set a title on the dialog?
Here's my code:
Activity:
customAdapter = new CustomAdapter(this);
GridView gridView = new GridView(this);
gridView.setAdapter(customAdapter);
gridView.setNumColumns(5);
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(gridView);
bottomSheetDialog.show();
CustomAdapter:
private final LayoutInflater inflater;
private List<String> sizeCodes;
public CustomAdapter(Context context) {
this.sizeCodes = Collections.emptyList();
this.inflater = LayoutInflater.from(context);
}
public CustomAdapter addItems(List<SizeData> items) {
sizeCodes = new ArrayList<>();
for (SizeData item : items)
sizeCodes.add(item.getSize());
notifyDataSetChanged();
return this;
}
@Override
public int getCount() {
return sizeCodes.size();
}
@Override
public String getItem(int position) {
return sizeCodes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = inflater.inflate(R.layout.item_size_picker, parent, false);
((TextView) convertView.findViewById(R.id.content)).setText(sizeCodes.get(position));
return convertView;
}
item_size_picker:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/content"
style="@style/Base.TextAppearance.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
java android customdialog
|
show 1 more comment
up vote
0
down vote
favorite
I have created a BottomSheetDialog
with a GridView
, but I know that BottomSheetDialog
can't set a title using the method .setTitle()
, so how can I set a title on the dialog?
Here's my code:
Activity:
customAdapter = new CustomAdapter(this);
GridView gridView = new GridView(this);
gridView.setAdapter(customAdapter);
gridView.setNumColumns(5);
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(gridView);
bottomSheetDialog.show();
CustomAdapter:
private final LayoutInflater inflater;
private List<String> sizeCodes;
public CustomAdapter(Context context) {
this.sizeCodes = Collections.emptyList();
this.inflater = LayoutInflater.from(context);
}
public CustomAdapter addItems(List<SizeData> items) {
sizeCodes = new ArrayList<>();
for (SizeData item : items)
sizeCodes.add(item.getSize());
notifyDataSetChanged();
return this;
}
@Override
public int getCount() {
return sizeCodes.size();
}
@Override
public String getItem(int position) {
return sizeCodes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = inflater.inflate(R.layout.item_size_picker, parent, false);
((TextView) convertView.findViewById(R.id.content)).setText(sizeCodes.get(position));
return convertView;
}
item_size_picker:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/content"
style="@style/Base.TextAppearance.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
java android customdialog
1
Why not just add your own titleView
? You could stick thatGridView
in verticalLinearLayout
with theTextView
above it, then pass the whole shebang tosetContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.
– Mike M.
Nov 21 at 18:40
MyGridView
is programatically created. Let me put the rest of the code on the question for a better understanding.
– Lucas Rufino
Nov 21 at 18:50
1
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
1
If you want to do it programatically, thenLinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert yourGridView
stuff, thencontent.addView(gridView); ... bottomSheetDialog.setContentView(content);
.
– Mike M.
Nov 21 at 19:01
1
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have created a BottomSheetDialog
with a GridView
, but I know that BottomSheetDialog
can't set a title using the method .setTitle()
, so how can I set a title on the dialog?
Here's my code:
Activity:
customAdapter = new CustomAdapter(this);
GridView gridView = new GridView(this);
gridView.setAdapter(customAdapter);
gridView.setNumColumns(5);
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(gridView);
bottomSheetDialog.show();
CustomAdapter:
private final LayoutInflater inflater;
private List<String> sizeCodes;
public CustomAdapter(Context context) {
this.sizeCodes = Collections.emptyList();
this.inflater = LayoutInflater.from(context);
}
public CustomAdapter addItems(List<SizeData> items) {
sizeCodes = new ArrayList<>();
for (SizeData item : items)
sizeCodes.add(item.getSize());
notifyDataSetChanged();
return this;
}
@Override
public int getCount() {
return sizeCodes.size();
}
@Override
public String getItem(int position) {
return sizeCodes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = inflater.inflate(R.layout.item_size_picker, parent, false);
((TextView) convertView.findViewById(R.id.content)).setText(sizeCodes.get(position));
return convertView;
}
item_size_picker:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/content"
style="@style/Base.TextAppearance.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
java android customdialog
I have created a BottomSheetDialog
with a GridView
, but I know that BottomSheetDialog
can't set a title using the method .setTitle()
, so how can I set a title on the dialog?
Here's my code:
Activity:
customAdapter = new CustomAdapter(this);
GridView gridView = new GridView(this);
gridView.setAdapter(customAdapter);
gridView.setNumColumns(5);
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(gridView);
bottomSheetDialog.show();
CustomAdapter:
private final LayoutInflater inflater;
private List<String> sizeCodes;
public CustomAdapter(Context context) {
this.sizeCodes = Collections.emptyList();
this.inflater = LayoutInflater.from(context);
}
public CustomAdapter addItems(List<SizeData> items) {
sizeCodes = new ArrayList<>();
for (SizeData item : items)
sizeCodes.add(item.getSize());
notifyDataSetChanged();
return this;
}
@Override
public int getCount() {
return sizeCodes.size();
}
@Override
public String getItem(int position) {
return sizeCodes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = inflater.inflate(R.layout.item_size_picker, parent, false);
((TextView) convertView.findViewById(R.id.content)).setText(sizeCodes.get(position));
return convertView;
}
item_size_picker:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/content"
style="@style/Base.TextAppearance.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
java android customdialog
java android customdialog
edited Nov 21 at 18:53
asked Nov 21 at 18:32
Lucas Rufino
217
217
1
Why not just add your own titleView
? You could stick thatGridView
in verticalLinearLayout
with theTextView
above it, then pass the whole shebang tosetContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.
– Mike M.
Nov 21 at 18:40
MyGridView
is programatically created. Let me put the rest of the code on the question for a better understanding.
– Lucas Rufino
Nov 21 at 18:50
1
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
1
If you want to do it programatically, thenLinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert yourGridView
stuff, thencontent.addView(gridView); ... bottomSheetDialog.setContentView(content);
.
– Mike M.
Nov 21 at 19:01
1
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31
|
show 1 more comment
1
Why not just add your own titleView
? You could stick thatGridView
in verticalLinearLayout
with theTextView
above it, then pass the whole shebang tosetContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.
– Mike M.
Nov 21 at 18:40
MyGridView
is programatically created. Let me put the rest of the code on the question for a better understanding.
– Lucas Rufino
Nov 21 at 18:50
1
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
1
If you want to do it programatically, thenLinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert yourGridView
stuff, thencontent.addView(gridView); ... bottomSheetDialog.setContentView(content);
.
– Mike M.
Nov 21 at 19:01
1
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31
1
1
Why not just add your own title
View
? You could stick that GridView
in vertical LinearLayout
with the TextView
above it, then pass the whole shebang to setContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.– Mike M.
Nov 21 at 18:40
Why not just add your own title
View
? You could stick that GridView
in vertical LinearLayout
with the TextView
above it, then pass the whole shebang to setContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.– Mike M.
Nov 21 at 18:40
My
GridView
is programatically created. Let me put the rest of the code on the question for a better understanding.– Lucas Rufino
Nov 21 at 18:50
My
GridView
is programatically created. Let me put the rest of the code on the question for a better understanding.– Lucas Rufino
Nov 21 at 18:50
1
1
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
1
1
If you want to do it programatically, then
LinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert your GridView
stuff, then content.addView(gridView); ... bottomSheetDialog.setContentView(content);
.– Mike M.
Nov 21 at 19:01
If you want to do it programatically, then
LinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert your GridView
stuff, then content.addView(gridView); ... bottomSheetDialog.setContentView(content);
.– Mike M.
Nov 21 at 19:01
1
1
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418486%2fhow-to-set-a-title-on-bottomsheetdialog-with-grid%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why not just add your own title
View
? You could stick thatGridView
in verticalLinearLayout
with theTextView
above it, then pass the whole shebang tosetContentView()
. You could continue to do it programatically, or you could make a layout for it to inflate and setup before you pass it.– Mike M.
Nov 21 at 18:40
My
GridView
is programatically created. Let me put the rest of the code on the question for a better understanding.– Lucas Rufino
Nov 21 at 18:50
1
We don't need it. You've shown enough. My first comment still applies.
– Mike M.
Nov 21 at 18:52
1
If you want to do it programatically, then
LinearLayout content = new LinearLayout(this); content.setOrientation(LinearLayout.VERTICAL); TextView title = new TextView(this); title.setText("Your Title"); content.addView(title);
, then insert yourGridView
stuff, thencontent.addView(gridView); ... bottomSheetDialog.setContentView(content);
.– Mike M.
Nov 21 at 19:01
1
OMG, I'm feeling stupid right now hahahahaha. Thanks, it works.
– Lucas Rufino
Nov 21 at 19:31