simpleAdapter代码



    
    
    
    

    



package com.example.simpleadapater;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.os.Build;

public class MainActivity extends Activity {

	String[]data={"apple","banana","grape","peach","pear","strawberry","mango","watermelon","orange"};
	private List> alList;
	private ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        listView=(ListView) findViewById(R.id.listView);
        alList=new ArrayList>();
        SimpleAdapter adapter=new SimpleAdapter(this, GetData(), R.layout.item, new String[]{"pic","te","pri"}, new int[]{R.id.image,R.id.text,R.id.price});
        listView.setAdapter(adapter);
    }
    
    public List> GetData()
    {
    	
    	Mapmap0=new HashMap();
    	map0.put("pic", R.drawable.ic_apple);
    	map0.put("te", data[0]);
    	map0.put("pri", "¥2.5");
    	alList.add(map0);
    	Mapmap1=new HashMap();
    	map1.put("pic", R.drawable.ic_banana);
    	map1.put("te", data[1]);
    	map1.put("pri", "¥3.5");
    	alList.add(map1);
    	Mapmap2=new HashMap();
    	map2.put("pic", R.drawable.ic_grape);
    	map2.put("te", data[2]);
    	map2.put("pri", "¥5.5");
    	alList.add(map2);
    	Mapmap3=new HashMap();
    	map3.put("pic", R.drawable.ic_peach);
    	map3.put("te", data[3]);
    	map3.put("pri", "¥22");
    	alList.add(map3);
    	Mapmap4=new HashMap();
    	map4.put("pic", R.drawable.ic_pear);
    	map4.put("te", data[4]);
    	map4.put("pri", "¥4.5");
    	alList.add(map4);
    	Mapmap5=new HashMap();
    	map5.put("pic", R.drawable.ic_strawberry);
    	map5.put("te", data[5]);
    	map5.put("pri", "¥6.5");
    	alList.add(map5);
    	Mapmap6=new HashMap();
    	map6.put("pic", R.drawable.ic_mango);
    	map6.put("te", data[6]);
    	map6.put("pri", "¥7.5");
    	alList.add(map6);
    	Mapmap7=new HashMap();
    	map7.put("pic", R.drawable.ic_watermelon);
    	map7.put("te", data[7]);
    	map7.put("pri", "¥9.5");
    	alList.add(map7);
    	Mapmap8=new HashMap();
    	map8.put("pic", R.drawable.ic_orange);
    	map8.put("te", data[8]);
    	map8.put("pri", "¥4.5");
    	alList.add(map8);
    
    	
    	return alList;
    }


}


你可能感兴趣的:(simpleAdapter代码)