如何运行镜像并获取新的镜像使用处理程序



我如何运行并获得新图像,我是安卓系统的新手,我正在使用eclipse进行这个项目,我不知道如何使其运行,有人能告诉我如何获得它吗?

完整代码主活动:

Handler handler = new Handler();
EditText inputUrl;
OnClickListener getImageBtnOnClick = new OnClickListener() {
    public void onClick(View view) {
        Context context = view.getContext();
        Editable ed = inputUrl.getText();
        Drawable image = ImageOperations(context,ed.toString(),"image.jpg");
        ImageView imgView = new ImageView(context);
        imgView = (ImageView)findViewById(R.id.imageView1);
        imgView.setImageDrawable(image);
        Handler handler = new Handler(); 
        handler.postDelayed(new Runnable() { 
                 public void run() { 
                 } 
            }, 10000);     
    }
};

=========================================================================

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    inputUrl = ((EditText)findViewById(R.id.editText1));
    inputUrl.setSingleLine();
    inputUrl.setTextSize(11);
    Button getImageButton = (Button)findViewById(R.id.button1);
    getImageButton.setOnClickListener(getImageBtnOnClick);
}
private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
    try {
        InputStream is = (InputStream) this.fetch(url);
        Drawable d = Drawable.createFromStream(is, "src");
        return d;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
public Object fetch(String address) throws MalformedURLException,IOException {
    URL url = new URL(address);
    Object content = url.getContent();
    return content;
}

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="18dp"
    android:ems="10" />
<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/editText1"
    android:text="Button" />
<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/button1"
    android:layout_marginTop="21dp"
    android:src="@drawable/ic_action_search" />

这是的问题

final ImageView imgView = new ImageView(context);

最新更新