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

    转自:http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html

    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);
                    }
                }
                 
            });
        }
    }
  • 相关阅读:
    程序员面试中有几大法则
    实现立方体旋转
    为什么技术与产品沟通起来总是那么痛苦
    移动互联网下半场的面试真经,让你进入 BAT 不再是梦
    Javascript+H5实现打小地鼠游戏
    Python多进程应用
    Python数据分析笔记:聚类算法之K均值
    给新手程序员的16个工作必备小妙招,省下时间去LOL吧!
    MySQL数据库开发常见问题及优化
    java中的四种引用类型
  • 原文地址:https://www.cnblogs.com/cugwx/p/3792431.html
Copyright © 2011-2022 走看看