zoukankan      html  css  js  c++  java
  • android捕获ListView中每个item点击事件

    package com.wps.android;
     
    import java.util.ArrayList;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
     
    public class Layouts extends Activity {
        /** Called when the activity is first created. */
        private ListView mylistview;
        private ArrayList<String> list = new ArrayList<String>();
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mylistview = (ListView)findViewById(R.id.listview);
            list.add("LinearLayout");
            list.add("AbsoluteLayout");
            list.add("TableLayout");
            list.add("RelativeLayout");
            list.add("FrameLayout");
            ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>
                                (this,android.R.layout.simple_list_item_1,list);
            mylistview.setAdapter(myArrayAdapter);
            /*mylistview.setOnTouchListener(new OnTouchListener(){
     
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    if(event.getAction() == MotionEvent.ACTION_DOWN)
                    {
                        mylistview.setBackgroundColor(Color.BLUE);
                    }
                    return false;
                }
                 
            });*/
            mylistview.setOnItemClickListener(new OnItemClickListener(){
     
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
                    if(list.get(arg2).equals("LinearLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.LINEARLAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("AbsoluteLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("TableLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.TABLELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("RelativeLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.RELATIVELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("FrameLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.FRAMELAYOUT");
                        startActivity(intent);
                    }
                }
                 
            });
        }
    }
    package com.wps.android;
     
    import java.util.ArrayList;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
     
    public class Layouts extends Activity {
        /** Called when the activity is first created. */
        private ListView mylistview;
        private ArrayList<String> list = new ArrayList<String>();
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mylistview = (ListView)findViewById(R.id.listview);
            list.add("LinearLayout");
            list.add("AbsoluteLayout");
            list.add("TableLayout");
            list.add("RelativeLayout");
            list.add("FrameLayout");
            ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>
                                (this,android.R.layout.simple_list_item_1,list);
            mylistview.setAdapter(myArrayAdapter);
            /*mylistview.setOnTouchListener(new OnTouchListener(){
     
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    if(event.getAction() == MotionEvent.ACTION_DOWN)
                    {
                        mylistview.setBackgroundColor(Color.BLUE);
                    }
                    return false;
                }
                 
            });*/
            mylistview.setOnItemClickListener(new OnItemClickListener(){
     
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
                    if(list.get(arg2).equals("LinearLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.LINEARLAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("AbsoluteLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("TableLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.TABLELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("RelativeLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.RELATIVELAYOUT");
                        startActivity(intent);
                    }
                    if(list.get(arg2).equals("FrameLayout"))
                    {
                        Intent intent = new Intent("com.wps.android.FRAMELAYOUT");
                        startActivity(intent);
                    }
                }
                 
            });
        }
    }
  • 相关阅读:
    性能测试四十五:性能测试策略
    性能测试四十四:性能优化思路
    性能测试四十三:数据库监控的指标
    性能测试四十二:sql案例之联合索引最左前缀
    性能测试四十一:sql案例之慢sql配置、执行计划和索引
    性能测试四十:Mysql存储过程造数据
    性能测试三十九:Jprofiler分析CPU过高和响应时间长的问题
    delphiIDE 把 window 桌面改慢后的 还原方法
    TStringList 善用 value['names'] 即使value 是带=号的值都没有关系呵呵 ,我靠 强,以后就用这个了,key=value首选
    TStringList,快速解析 查找测试。。。很有用,再也不用 FOR 循环了
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4762620.html
Copyright © 2011-2022 走看看