• 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);
                    }
                }
                 
            });
        }
    }
  • 相关阅读:
    js debounce防抖技术
    我在项目中es6中数组的常用方法
    windows 部署Nginx转发http2.0协议
    AES加密,C#和java相同
    asp:Button js弹出提示框信息
    服务器不重启安装Asp.net Core 程序包
    C# string.Join的用法
    IIS部署asp.net core webapi
    ASP.net 加载不了字体Failed to load resource: the server responded with a status of 404 (Not Found)
    Windows Redis 取消保护模式C#进行访问
  • 原文地址:https://www.cnblogs.com/cugwx/p/3792431.html
Copyright © 2020-2023  润新知