zoukankan      html  css  js  c++  java
  • ListView

    package com.test.android;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.Toast;

    public class HelloAndroid extends Activity {
        
    private static final String[] m_arr = {"第一组","第二组","第三组"};
        
    /** Called when the activity is first created. */
        @Override
        
    public void onCreate(Bundle savedInstanceState) {
            
    super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            ListView lv 
    = (ListView)findViewById(R.id.ListView01);
            ArrayAdapter
    <String> ada = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, m_arr);
            lv.setAdapter(ada);
            lv.setOnItemClickListener(
    new ListView.OnItemClickListener(){
                
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
                    dispToast(
    "选择的是"+ m_arr[arg2]);
                }
            });
            lv.setOnItemSelectedListener(
    new ListView.OnItemSelectedListener(){
                
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
                    dispToast(
    "滚动的是" + m_arr[arg2]);
                    arg0.setVisibility(View.VISIBLE);
                }
                
    public void onNothingSelected(AdapterView<?> arg0){
                    
    //
                }
            });
       }
        
    public void dispToast(String str){
            Toast.makeText(
    this, str, Toast.LENGTH_SHORT).show();
        }
    }
  • 相关阅读:
    【AS3代码】小游戏打飞机源代码
    【AS3代码】键盘的输入和输出
    PHP多维数组排序
    【AS3代码】一个完整的游戏框架
    【AS3代码】小画板升级版(带重绘回放和清空功能)
    Liunx命令工作总结(1)
    Java NIO基础 我们到底能走多远系列(17)
    ibatis 一对多 解决方案
    图片上传+预览+剪切解决方案我们到底能走多远系列(20)
    Liunx命令工作总结(2)
  • 原文地址:https://www.cnblogs.com/wjhx/p/1679987.html
Copyright © 2011-2022 走看看