hello guys, am very new to android development, ans am trying to do my best to learn it,I have json output created from one of my PHP projects
here is my output

    "id": "1",
    "name": "BEiN HD 1",
    "link": "http:\/\/www.mysite.com\/tv4.ogg",
    "image": "http:\/\/www.mysite.com\/images\/jsc8.png"
    "id": "2",
    "name": "BEiN HD 2",
    "link": "http:\/\/www.mysite.com\/tv4.ogg",
    "image": "http:\/\/www.mysite.com\/images\/jsc2.png"
    "id": "3",
    "name": "Comedy",
    "link": "http:\/\/www.mysite.com\/tv4.ogg",
    "image": "http:\/\/www.mysite.com\/images\/comedy.png"

I want to read this file and create ImageButons dynamically for it src image will be the picture from JSON array.
any tutorials to achive this ?

Recommended Answers

All 4 Replies

Am sorry i forgot to add my test code for creating buttons, how to set image src to buttons from JSON url.

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {
        final LinearLayout lm = (LinearLayout) findViewById(R.id.ll);
        // create the layout params that will be used to define how your
        // button will be displayed
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //Create four
        for(int j=0;j<=6;j++)
            // Create LinearLayout
            ScrollView SV = new ScrollView(this);
            // Create Button
            final Button btn = new Button(this);
            // Give button an ID
            btn.setText("CH" + (j+1));
            // set the layoutParams on the button

            final int index = j;
            // Set click listener for button
            btn.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                            "Clicked Button Index :" + index,


            //Add button to LinearLayout
            //Add button to LinearLayout defined in XML

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;

        return super.onOptionsItemSelected(item);

To understand your question better:

A. Are you asking about how to process JSON in Java?
B. Are you asking how to set button image URL from parsed/processed JSON?

Well honestly I was asking for how to process JSON in java, but I relized I can't put direct links for images as source,then I found a way to make this happen

public static Drawable LoadImageFromWebOperations(String url) {
    try {
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return d;
    } catch (Exception e) {
        return null;

so my problem now is
A. Are you asking about how to process JSON in Java? :)
sorry for this mess.

Simplest way (well by me) is GSON (user guide and API). Create model of the class,

public class Movie {
    int id;
    String name;
    String link;

get your JSON (not sure if you fetching raw stream that you push to reader or you actually getting string) and tell GSON to parse it based on this sample would be

Gson gson = new Gson();
Movie[] movies = gson.fromJson(jsonString, Movie.class);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.