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); } } }); } }

更多相关文章

  1. Android(安卓)环境搭建
  2. android studio调试c/c++代码
  3. 在Fragment中设置控件点击方法,执行失败。
  4. [android]在上下文菜单的选中事件中获取列表选中的元素
  5. Android,LIstView中的OnItemClick点击无效的解决办法
  6. Android之adb环境变量配置
  7. android 多点触控
  8. Android上的模拟点击
  9. Android解决父控件拦截子控件手势滑动事件的问题

随机推荐

  1. Android(安卓)Studio 上传aar(Library)到
  2. Material Design之TabLayout的用法(标题栏
  3. Android(安卓)Fragment中监听事件
  4. 使用TestProject Python SDK创建移动Appi
  5. 带你一步一步深入Handler源码,拿下面试官
  6. android自动化测试CTS源码分析之一
  7. Android(安卓)时间间隔显示处理 1小时前
  8. android Activity之间跳转。
  9. Android桌面组件开发例子
  10. android中的Handler和Callback机制