/*
* 转转轮盘,Spinner Wheel特效
*/
import 略;
public class Ex10_09Activity extends Activity {
private ListView listView;
private TextView textView;
String[] s1 = { "", "", "办公室", "厕所", "客厅", "厨房", "学校", "家里", "车上", "房间",
"", "" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.ListView01);
textView = (TextView) findViewById(R.id.TextView01);
// 将字符串放到ArraryAdapter中
ArrayAdapter<String> list1 = new ArrayAdapter<String>(this,
R.layout.file_row, s1);
// 设置ListView的Adapter
listView.setAdapter(list1);
// 卷动时透明化
listView.setCacheColorHint(00000000);
listView.setFastScrollEnabled(true);
// 雾化边缘
listView.setFadingEdgeLength(100);
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
// 取得第一个显示的下两格的值
textView.setText(s1[firstVisibleItem] + 2);
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int id,
long arg3) {
// TODO Auto-generated method stub
listView.setSelectionFromTop(id - 2, 0);
textView.setText(s1[id]);
}
});
listView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int id,
long arg3) {
// TODO Auto-generated method stub
textView.setText(s1[id]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
下面我们来看看程序运行后的结果: