package com.turboradio.googlesdk;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Ex4_20 extends ListActivity {
private int selectedItem = -1;
private String [] mString;
private ArrayAdapter<String> mla;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
/**
* ListView的列表单机事件
*/
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
selectedItem = position;
Toast.makeText(this, mString[selectedItem], Toast.LENGTH_LONG).show();
super.onListItemClick(l, v, position, id);
}
/**生成Menu菜单**/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
int idGroup1 = 0;
int orderMenuItem1 = Menu.NONE;
int orderMenuItem2 = Menu.NONE+1;
menu.add(idGroup1, orderMenuItem1, 0, "显示列表1");
menu.add(idGroup1, orderMenuItem2, 1, "显示列表2");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case 0:
Toast.makeText(Ex4_20.this, "1", Toast.LENGTH_LONG).show();
mString = new String[]{"张三","李四","王五","赵六"};
mla = new ArrayAdapter<String>(Ex4_20.this,android.R.layout.simple_list_item_1,mString);
Ex4_20.this.setListAdapter(mla);
break;
case 1:
Toast.makeText(Ex4_20.this, "2", Toast.LENGTH_LONG).show();
mString = new String[]{"JAVA","C","C++","PHP","OBJECTIVE-C"};
mla = new ArrayAdapter<String>(Ex4_20.this,android.R.layout.simple_list_item_1,mString);
Ex4_20.this.setListAdapter(mla);
break;
}
return super.onOptionsItemSelected(item);
}
}