我是否認爲你有一個圖像按鈕,當你點擊它你想要去那些URL之一嗎?
嘗試添加到您的圖像按鈕。
imageButton.setOnClickListener(new locatorButtonClickListener());
private class imageButtonListener implements OnClickListener
{
@Override
public void onClick(View button) {
new DisplayImageFromUrl((ImageButton) findViewById(R.id.imageButtonEnd), this).execute(//Enter your link here);
}
UPDATE 嘗試使用此異步任務
//Display image to bitmap using URL
public class DisplayImageFromUrl extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
Context context1;
ProgressDialog pd;
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(context1);
pd.setMessage("Loading Images...");
pd.show();
}
public DisplayImageFromUrl(ImageView bmImage, Context context) {
this.bmImage = bmImage;
this.context1 = context;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
pd.dismiss();
}
}
,並在你的活動這樣稱呼它。
new DisplayImageFromUrl((ImageButton) findViewById(R.id.imageButtonEnd), this).execute(//Enter your link here);
你在哪裏顯示這個初始網址?在網頁瀏覽?還是應用程序中的可點擊按鈕?試試[這](http://developer.android.com/training/basics/firstapp/starting-activity.html) – linus
基本上我設置一個圖像上的clicklistener。 – aQ1711