Skip to main content
Publicación reabierta por user13558, PaperBirdMaster, fedorqui, Mariano, Shaz
Mejorando gramática y formato. Cambiando título.
Origen Enlace
user13558
user13558

Petición de imagen httpHTTP en ImageView de Android

Estoy tratando que mediante una dirección web me descargue una imagen y que me la acople en un layoutlayout. Por ejemplo si quiero obtener esta imagen: https://www.google.es/images/branding/googleg/1x/googleg_standard_color_128dp.pngesta imagen y que a su vez la acople en un layoutlayout.

Código XMLXML:

Código JavaJava:

public class intelActivity extends FragmentActivity {

    /**
     * The pager widget, which handles animation and allows swiping horizontally
     * to access previous and next pages.
     */
    ViewPager pager = null;

    /**
     * The pager adapter, which provides the pages to the view pager widget.
     */
    MyFragmentPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intel);

        // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

        //StrictMode.setThreadPolicy(policy);


        ImageView graph = (ImageView) findViewById(R.id.graphImageView);
        //graph.setImageResource(R.drawable.graph);

        Picasso.with(this).load("http://chart.finance.yahoo.com/z?s=GOOG").into(graph);

        // Instantiate a ViewPager
        this.pager = (ViewPager) this.findViewById(R.id.viewPager);

        // Create an adapter with the fragments we show on the ViewPager
        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
                getSupportFragmentManager());
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 0));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.negativo), 1));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 2));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.negativo), 3));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 4));
        this.pager.setAdapter(adapter);

        new Thread()
        {
            public void run()
            {

                    while (true) {
                        try {
                        Thread.sleep(3000);
                            Stock stock = null;
                            try {
                                stock = YahooFinance.get("bz=f");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            BigDecimal PRUEBA = stock.getQuote().getChange();
                            BigDecimal price = stock.getQuote().getPrice();
                            BigDecimal change = stock.getQuote().getChangeInPercent();
                            BigDecimal peg = stock.getStats().getPeg();
                            BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

                            System.out.println(price);
                            System.out.println("----------------------------------");
                           // stock.print();

                    }
                catch(Exception ex)
                    {
                    }
                }
            }
     
        }.start();
 
    }
}

Petición de imagen http en ImageView de Android

Estoy tratando que mediante una dirección web me descargue una imagen y que me la acople en un layout. Por ejemplo si quiero obtener esta imagen: https://www.google.es/images/branding/googleg/1x/googleg_standard_color_128dp.png y que a su vez la acople en un layout.

Código XML:

Código Java:

public class intelActivity extends FragmentActivity {

/**
 * The pager widget, which handles animation and allows swiping horizontally
 * to access previous and next pages.
 */
ViewPager pager = null;

/**
 * The pager adapter, which provides the pages to the view pager widget.
 */
MyFragmentPagerAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intel);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    //StrictMode.setThreadPolicy(policy);


    ImageView graph = (ImageView) findViewById(R.id.graphImageView);
    //graph.setImageResource(R.drawable.graph);

    Picasso.with(this).load("http://chart.finance.yahoo.com/z?s=GOOG").into(graph);

    // Instantiate a ViewPager
    this.pager = (ViewPager) this.findViewById(R.id.viewPager);

    // Create an adapter with the fragments we show on the ViewPager
    MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
            getSupportFragmentManager());
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 0));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 1));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 2));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 3));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 4));
    this.pager.setAdapter(adapter);

    new Thread()
    {
        public void run()
        {

                while (true) {
                    try {
                    Thread.sleep(3000);
                        Stock stock = null;
                        try {
                            stock = YahooFinance.get("bz=f");
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        BigDecimal PRUEBA = stock.getQuote().getChange();
                        BigDecimal price = stock.getQuote().getPrice();
                        BigDecimal change = stock.getQuote().getChangeInPercent();
                        BigDecimal peg = stock.getStats().getPeg();
                        BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

                        System.out.println(price);
                        System.out.println("----------------------------------");
                       // stock.print();

                }
            catch(Exception ex)
                {
                }
            }
        }
 
    }.start();
 
}
}

Petición de imagen HTTP en ImageView de Android

Estoy tratando que mediante una dirección web me descargue una imagen y que me la acople en un layout. Por ejemplo si quiero obtener esta imagen y que a su vez la acople en un layout.

Código XML:

Código Java:

public class intelActivity extends FragmentActivity {

    /**
     * The pager widget, which handles animation and allows swiping horizontally
     * to access previous and next pages.
     */
    ViewPager pager = null;

    /**
     * The pager adapter, which provides the pages to the view pager widget.
     */
    MyFragmentPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intel);

        // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

        //StrictMode.setThreadPolicy(policy);


        ImageView graph = (ImageView) findViewById(R.id.graphImageView);
        //graph.setImageResource(R.drawable.graph);

        Picasso.with(this).load("http://chart.finance.yahoo.com/z?s=GOOG").into(graph);

        // Instantiate a ViewPager
        this.pager = (ViewPager) this.findViewById(R.id.viewPager);

        // Create an adapter with the fragments we show on the ViewPager
        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
                getSupportFragmentManager());
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 0));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.negativo), 1));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 2));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.negativo), 3));
        adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
                .getColor(R.color.positivo), 4));
        this.pager.setAdapter(adapter);

        new Thread()
        {
            public void run()
            {

                    while (true) {
                        try {
                        Thread.sleep(3000);
                            Stock stock = null;
                            try {
                                stock = YahooFinance.get("bz=f");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            BigDecimal PRUEBA = stock.getQuote().getChange();
                            BigDecimal price = stock.getQuote().getPrice();
                            BigDecimal change = stock.getQuote().getChangeInPercent();
                            BigDecimal peg = stock.getStats().getPeg();
                            BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

                            System.out.println(price);
                            System.out.println("----------------------------------");
                           // stock.print();

                    }
                catch(Exception ex)
                    {
                    }
                }
            }    
        }.start();
    }
}
se añadieron 3208 caracteres en el cuerpo
Origen Enlace
UnexpectedCharacter
  • 1.9k
  • 12
  • 41
  • 64

Adjunto códigoCódigo XML:

<LinearLayout
    android:id="@+id/graphLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/activityStockLinearLayout"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/graphImageView"
        android:layout_width="wrap_content"
        android:layout_height="243dp"
        app:srcCompat="@drawable/graph" />
</LinearLayout>

Código Java:

public class intelActivity extends FragmentActivity {

/**
 * The pager widget, which handles animation and allows swiping horizontally
 * to access previous and next pages.
 */
ViewPager pager = null;

/**
 * The pager adapter, which provides the pages to the view pager widget.
 */
MyFragmentPagerAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intel);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    //StrictMode.setThreadPolicy(policy);


    ImageView graph = (ImageView) findViewById(R.id.graphImageView);
    //graph.setImageResource(R.drawable.graph);

    Picasso.with(this).load("http://chart.finance.yahoo.com/z?s=GOOG").into(graph);

    // Instantiate a ViewPager
    this.pager = (ViewPager) this.findViewById(R.id.viewPager);

    // Create an adapter with the fragments we show on the ViewPager
    MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
            getSupportFragmentManager());
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 0));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 1));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 2));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 3));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 4));
    this.pager.setAdapter(adapter);

    new Thread()
    {
        public void run()
        {

                while (true) {
                    try {
                    Thread.sleep(3000);
                        Stock stock = null;
                        try {
                            stock = YahooFinance.get("bz=f");
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        BigDecimal PRUEBA = stock.getQuote().getChange();
                        BigDecimal price = stock.getQuote().getPrice();
                        BigDecimal change = stock.getQuote().getChangeInPercent();
                        BigDecimal peg = stock.getStats().getPeg();
                        BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

                        System.out.println(price);
                        System.out.println("----------------------------------");
                       // stock.print();

                }
            catch(Exception ex)
                {
                }
            }
        }

    }.start();

}
}

Adjunto código:

<LinearLayout
    android:id="@+id/graphLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/activityStockLinearLayout"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/graphImageView"
        android:layout_width="wrap_content"
        android:layout_height="243dp"
        app:srcCompat="@drawable/graph" />
</LinearLayout>

Código XML:

<LinearLayout
    android:id="@+id/graphLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/activityStockLinearLayout"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/graphImageView"
        android:layout_width="wrap_content"
        android:layout_height="243dp"
        app:srcCompat="@drawable/graph" />
</LinearLayout>

Código Java:

public class intelActivity extends FragmentActivity {

/**
 * The pager widget, which handles animation and allows swiping horizontally
 * to access previous and next pages.
 */
ViewPager pager = null;

/**
 * The pager adapter, which provides the pages to the view pager widget.
 */
MyFragmentPagerAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intel);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    //StrictMode.setThreadPolicy(policy);


    ImageView graph = (ImageView) findViewById(R.id.graphImageView);
    //graph.setImageResource(R.drawable.graph);

    Picasso.with(this).load("http://chart.finance.yahoo.com/z?s=GOOG").into(graph);

    // Instantiate a ViewPager
    this.pager = (ViewPager) this.findViewById(R.id.viewPager);

    // Create an adapter with the fragments we show on the ViewPager
    MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(
            getSupportFragmentManager());
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 0));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 1));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 2));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.negativo), 3));
    adapter.addFragment(ScreenSlidePageFragment.newInstance(getResources()
            .getColor(R.color.positivo), 4));
    this.pager.setAdapter(adapter);

    new Thread()
    {
        public void run()
        {

                while (true) {
                    try {
                    Thread.sleep(3000);
                        Stock stock = null;
                        try {
                            stock = YahooFinance.get("bz=f");
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        BigDecimal PRUEBA = stock.getQuote().getChange();
                        BigDecimal price = stock.getQuote().getPrice();
                        BigDecimal change = stock.getQuote().getChangeInPercent();
                        BigDecimal peg = stock.getStats().getPeg();
                        BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();

                        System.out.println(price);
                        System.out.println("----------------------------------");
                       // stock.print();

                }
            catch(Exception ex)
                {
                }
            }
        }

    }.start();

}
}
Publicación cerrada como "Necesita detalles o aclaraciones" por Jorgesys, Max Sandoval, dwarandae, fredyfx, Ventur
título editado
Enlace
UnexpectedCharacter
  • 1.9k
  • 12
  • 41
  • 64

Petición de imagen http en ImageView de Android

Origen Enlace
UnexpectedCharacter
  • 1.9k
  • 12
  • 41
  • 64
Loading