码迷,mamicode.com
首页 > 移动开发 > 详细

android捕获ListView中每个item点击事件

时间:2014-06-17 15:19:52      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:android   class   blog   code   java   http   

转自: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);
                }
            }
             
        });
    }
}

android捕获ListView中每个item点击事件,布布扣,bubuko.com

android捕获ListView中每个item点击事件

标签:android   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/cugwx/p/3792431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!