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);
    				}
    			}
            	
            });
        }
    }
    
  • 相关阅读:
    Go语言【第八篇】:Go语言变量作用域
    Go语言【第七篇】:Go函数
    Django 2.0 学习(10):Django 定制化
    Go语言【第六篇】:Go循环语句
    Go语言【第五篇】:Go条件语句
    Go语言【第四篇】:Go运算符
    Go语言【第二篇】:Go语法和数据类型
    苹果电脑自带python安装tensorflow一直有问题
    那些年深度学习所踩过的坑-第一坑
    C++基础知识--DAY3
  • 原文地址:https://www.cnblogs.com/pswzone/p/2389275.html
Copyright © 2011-2022 走看看