android动态向SPinner控件中添加数据 .

android动态向SPinner控件中添加数据 .

作者:fly 发布于:2014-2-13 8:39 分类:android

public class GroupPurchase extends Activity {   
    private Spinner changeCity;   
    private Button refresh, pre, next;   
    private TextView leftTime, detail, price, citygp;   
    private ImageView images;   
    private ArrayAdapter<String> adapter;   
    private List<String> allItems;   
    private String[] citys = { "北京市", "上海市", "天津市", "福州市" };   
  
    @Override  
    public void onCreate(Bundle savedInstanceState) {   
        super.onCreate(savedInstanceState);   
        setContentView(R.layout.main);   
        initView();   
           
        allItems = new ArrayList<String>();   
        for (int i = 0; i < citys.length; i++) {   
            allItems.add(citys[i]);   
        }   
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, allItems);   
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);   
        changeCity.setAdapter(adapter);   
        changeCity.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {   
                    @Override  
                    public void onItemSelected(AdapterView<?> arg0, View arg1,   
                            int arg2, long arg3) {   
                        citygp.setText(changeCity.getSelectedItem().toString() + "今天的团购");   
                        Log.i("info-----------", changeCity.getSelectedItem().toString());   
                    }   
  
                    @Override  
                    public void onNothingSelected(AdapterView<?> arg0) {   
                    }   
                });   
  
        pre.setOnClickListener(new View.OnClickListener() {   
            @Override  
            public void onClick(View v) {   
                Log.i("info-----------", "prefer button has pressed!!!");   
            }   
        });   
  
        next.setOnClickListener(new View.OnClickListener() {   
            @Override  
            public void onClick(View v) {   
                Log.i("info-----------", "next button has pressed!!!");   
            }   
        });   
    }   
  
}  

发表评论:

 
Powered by emlog sitemap