android 捕获ListView 的item点击事件》
2015-12-04 15:54
295 查看
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 button设计模拟器
- android string.xml中显示特殊常用的字符方法
- Android四大组件--Activity启动过程(全)
- Android第三方开源:统计图表MPAndroidChart
- android上的JAVA8:使用retrolambda
- 自建 Android 源码 git/repo 仓库
- 前端之Android入门(6):屏幕适配
- Android 下实用的图片压缩
- 前端之Android入门(5):MVC模式(下)
- 前端之Android入门(4):MVC模式(中)
- Android自定义View----1. 自定义组合控件
- 前端之Android入门(3):MVC模式(上)
- 前端之Android入门(1):环境配置
- Handler
- ListView
- 图文详解Android Studio搭建Android集成开发环境的过程
- Android整机源码如何轻松下载?清华大学Android源码镜像
- Android studio 配置SVN 报错问题解决
- 查看Android应用签名信息
- AndroidStudio NDK项目HelloJni