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){
}
}
}