我已經創建了一個程序,它從服務器讀取文件以構建列表視圖。然後它在後臺加載一個圖像。現在圖像被加載到一個圖像視圖,以確保它的工作。如何將圖像加載到我的listview imageview行?如何在創建listvue後更改圖像?
public class Welcome extends ListActivity {
/** Called when the activity is first created. */
// data to load from html file
ArrayList<String> images;
ArrayList<String> Links;
ArrayList<String> LinkName;
ArrayList<String> Price;
int y;
ArrayList<String> ted;
int i;
String[] items={"CASUAL","DRESSES","CAREER","OUTWEAR","FOOTWEAR",
"JEWELRY","ACCESSORIES"};
private HttpClient client;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// data read in can be from 1-10
images=new ArrayList();
Links=new ArrayList();
LinkName=new ArrayList();
Price=new ArrayList();
// load in arrays from a file on a web server
Loaddata();
// create a listvue based on the data loaded from the server
setListAdapter(new IconicAdapter(this));
// load in biytmap
download();
} // end function
class IconicAdapter extends ArrayAdapter {
Activity context;
IconicAdapter(Activity context) {
super(context, R.layout.row, LinkName);
this.context=context;
}
public View getView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View row=inflater.inflate(R.layout.row, null);
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(LinkName.get(position));
return(row);
}
}
private void download(){
new AsyncTask<Void, Void, Bitmap>(){
@Override
protected Bitmap doInBackground(Void... params) {
HttpClient client = new DefaultHttpClient();
try {
String uri = "http://www.besttechsolutions.biz/icon.png";
HttpGet request = new HttpGet(uri);
HttpResponse response = client.execute(request);
return BitmapFactory.decodeStream(response.getEntity().getContent());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap image) {
if(image == null){
Log.d("ted", "could not download image");
// Toast.makeText(Main.this, "Download failed", Toast.LENGTH_LONG).show();
}
else{
// losd into ListView
// ImageView myimage = (ImageView) findViewById(R.id.myimage);
// myimage.setImageBitmap(image);
}
}
}.execute();
}
你想顯示圖像在每一行像這樣的文字[圖像文字/標籤]? – 2011-04-01 13:09:39