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>









share|improve this question




















  • 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










  • 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 your GridView stuff, then content.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















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>









share|improve this question




















  • 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










  • 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 your GridView stuff, then content.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













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>









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 18:53

























asked Nov 21 at 18:32









Lucas Rufino

217




217








  • 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










  • 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 your GridView stuff, then content.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




    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






  • 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 your GridView stuff, then content.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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)