android捕获ListView中每个item点击事件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); } } }); } } |
以上是关于android捕获ListView中每个item点击事件的主要内容,如果未能解决你的问题,请参考以下文章
android中的Listview设置刷新时,Item是当前的Item,而不是第一个Item
android 如何在listview中点击当前Item中的按钮删除该item
android的ListView中如何设置长按Item的时候该Item背景变色
Android 在listview里itme中有imagebutton 怎么监听这个button?
我的Android进阶之旅------>Android中ListView中嵌套(ListView)控件时item的点击事件不起作的问题解决方法