zoukankan      html  css  js  c++  java
  • ListView及其ArrayAdapter的应用

    public class ListViewDemo_MainActivity extends Activity{
        public void onCreate(Bundle savedInstanceState);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TextView textview = (TextView)findViewById(R.id.textview);
    ListView mylistview = (ListView) findViewById(R.id.listview);
    AdapterArray<String> list = new AdapterArray<String>(this,android.R.layout.simple_spinner_dropdown_item,
    new String[]{"football","Android","Computer","Apple"});
    
    mylistview.setAdapter(list);
    mylistview.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(new AdapterView<?>arg0,View arg1,int arg2,Long arg3){
    
    String result = arg0.getItemAtPosition(arg2).toString();
    Toast.makeText(ListViewDemo_MainActivity.this,result,Toast.LENGTH_SHORT).show();
    textView.setText(result);
    
    }
    });
    
    mylistview.setOnItemSelectedListener(new OnItemSelectedListener(){
    public void onItemSelected(AdapterView<?>parent,View view,int position,long id){
    //用于能上下选择的手机
    }
    public void onNothingSelected(AdapterView<?>parent){
    }
    }
    
    }
  • 相关阅读:
    函数
    文件处理及处理模式
    字符编码
    元组,字典和集合的用法
    数字类型、字符串和列表
    计算机硬件介绍
    数据类型及语法介绍
    初识python
    设计模式
    最近的时候
  • 原文地址:https://www.cnblogs.com/CCCrunner/p/11782064.html
Copyright © 2011-2022 走看看