Make New Button For Each JSON ObjectSafely turning a JSON string into an objectHow do I efficiently iterate over each entry in a Java Map?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?Strange out of memory issue while loading an image to a Bitmap objectWhat is the correct JSON content type?How do I test for an empty JavaScript object?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?
Which skill would I use for ventriloquism?
Simulate a pool using multithreading in Python
Will a nuclear country use nuclear weapons if attacked by conventional means by another nuclear country?
How to identify a (personal) Canon Sue?
CO₂ level is high enough that it reduces cognitive ability. Isn't that a reason to worry?
My name causes an issue with any booking! (names end with MR and MRS)
Canonical reference for Chern characteristic classes
How do I find the unknown program enabled during Start-Up?
Windows 10 ruined my GRUB menu
How does the sorcerer's Careful Spell Metamagic option work with the Thunderwave spell?
How to use FDE without needing to share the encryption password
Pi to the power y, for small y's
count network interfaces in bash
Which modifier shown in the D&D Beyond character sheet do I add to attack rolls with my longbow?
How much money is needed to prove you can support yourself with ESTA
Implement the Max-Pooling operation from Convolutional Neural Networks
Why does Smaug have 4 legs in the 1st movie but only 2 legs in the 2nd?
Why did the Bohr Model Successfully calculate some of the energy levels in hydrogen?
Need Good OOP Design For World and Countries Problem
When should we use "Got it?" and "Get it?"
Google just EOLed the original Pixel. How long until it's a brick?
How much money would I need to feel secure in my job?
What on earth is this small wall-mounted computer?
Dicht antonym - what is it?
Make New Button For Each JSON Object
Safely turning a JSON string into an objectHow do I efficiently iterate over each entry in a Java Map?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?Strange out of memory issue while loading an image to a Bitmap objectWhat is the correct JSON content type?How do I test for an empty JavaScript object?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am trying to get my app to make a button for each item category from my JSON and set the button image and title in the app remotely. How can I do this so that I can add a new category from my database and in the app it will create a new button for that category with image and title?
Any help is much appreciated.
Unfortunately I don’t have much code at the moment to show.
java android json
add a comment
|
I am trying to get my app to make a button for each item category from my JSON and set the button image and title in the app remotely. How can I do this so that I can add a new category from my database and in the app it will create a new button for that category with image and title?
Any help is much appreciated.
Unfortunately I don’t have much code at the moment to show.
java android json
add a comment
|
I am trying to get my app to make a button for each item category from my JSON and set the button image and title in the app remotely. How can I do this so that I can add a new category from my database and in the app it will create a new button for that category with image and title?
Any help is much appreciated.
Unfortunately I don’t have much code at the moment to show.
java android json
I am trying to get my app to make a button for each item category from my JSON and set the button image and title in the app remotely. How can I do this so that I can add a new category from my database and in the app it will create a new button for that category with image and title?
Any help is much appreciated.
Unfortunately I don’t have much code at the moment to show.
java android json
java android json
edited Mar 28 at 22:28
EJoshuaS - Reinstate Monica
8,04910 gold badges33 silver badges52 bronze badges
8,04910 gold badges33 silver badges52 bronze badges
asked Mar 28 at 21:52
Mohammed SalaamMohammed Salaam
64 bronze badges
64 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
You can simply take a horizontal/vertical linear layout in your xml that will act as a container. Put that LinearLayout in Horizontal or Vertical ScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
In your Activity :
for (int i = 0; i < yourArray.length(); i++)
Button btn = new Button(this);
btn.setId(i);
btn.setTag(i);
btn.setText("Button " + (i+1));
btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_notifications_black_24dp), null, null, null);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("BTN", view.getTag().toString());
);
linearLayout.addView(btn);
Similarly, you can add any view you want in the LinearLayout either horizontally or vertically. Have a look at the attached screenshots.
add a comment
|
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',
autoActivateHeartbeat: false,
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/4.0/"u003ecc by-sa 4.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
);
);
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%2f55407416%2fmake-new-button-for-each-json-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can simply take a horizontal/vertical linear layout in your xml that will act as a container. Put that LinearLayout in Horizontal or Vertical ScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
In your Activity :
for (int i = 0; i < yourArray.length(); i++)
Button btn = new Button(this);
btn.setId(i);
btn.setTag(i);
btn.setText("Button " + (i+1));
btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_notifications_black_24dp), null, null, null);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("BTN", view.getTag().toString());
);
linearLayout.addView(btn);
Similarly, you can add any view you want in the LinearLayout either horizontally or vertically. Have a look at the attached screenshots.
add a comment
|
You can simply take a horizontal/vertical linear layout in your xml that will act as a container. Put that LinearLayout in Horizontal or Vertical ScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
In your Activity :
for (int i = 0; i < yourArray.length(); i++)
Button btn = new Button(this);
btn.setId(i);
btn.setTag(i);
btn.setText("Button " + (i+1));
btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_notifications_black_24dp), null, null, null);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("BTN", view.getTag().toString());
);
linearLayout.addView(btn);
Similarly, you can add any view you want in the LinearLayout either horizontally or vertically. Have a look at the attached screenshots.
add a comment
|
You can simply take a horizontal/vertical linear layout in your xml that will act as a container. Put that LinearLayout in Horizontal or Vertical ScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
In your Activity :
for (int i = 0; i < yourArray.length(); i++)
Button btn = new Button(this);
btn.setId(i);
btn.setTag(i);
btn.setText("Button " + (i+1));
btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_notifications_black_24dp), null, null, null);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("BTN", view.getTag().toString());
);
linearLayout.addView(btn);
Similarly, you can add any view you want in the LinearLayout either horizontally or vertically. Have a look at the attached screenshots.
You can simply take a horizontal/vertical linear layout in your xml that will act as a container. Put that LinearLayout in Horizontal or Vertical ScrollView like below.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
In your Activity :
for (int i = 0; i < yourArray.length(); i++)
Button btn = new Button(this);
btn.setId(i);
btn.setTag(i);
btn.setText("Button " + (i+1));
btn.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_notifications_black_24dp), null, null, null);
btn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Log.d("BTN", view.getTag().toString());
);
linearLayout.addView(btn);
Similarly, you can add any view you want in the LinearLayout either horizontally or vertically. Have a look at the attached screenshots.
answered Mar 28 at 23:07
Ambar JainAmbar Jain
4494 silver badges10 bronze badges
4494 silver badges10 bronze badges
add a comment
|
add a comment
|
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.
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%2f55407416%2fmake-new-button-for-each-json-object%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