Skip to main content
4 de 4
Mejorando gramática y formato. Cambiando título.
user avatar
user avatar

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:

<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();
    }
}
UnexpectedCharacter
  • 1.9k
  • 12
  • 41
  • 64