博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android捕获ListView中每个item点击事件
阅读量:6758 次
发布时间:2019-06-26

本文共 2114 字,大约阅读时间需要 7 分钟。

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

转载地址:http://zvweo.baihongyu.com/

你可能感兴趣的文章
Javascript学习6 - 类、对象、继承
查看>>
Java并发编程:如何创建线程?
查看>>
Faster R-CNN CPU环境搭建
查看>>
IOS在线安装App
查看>>
base 镜像 - 每天5分钟玩转容器技术(10)
查看>>
六、编写第一个应用【外部nodejs调用】
查看>>
利用DNSlog回显Weblogic(CVE-2017-10271) 漏洞执行命令结果
查看>>
第16件事 愿景和目标要接地气
查看>>
细嚼慢咽 Mongoose 5
查看>>
Direct3D 11 Tutorial 7:Texture Mapping and Constant Buffers_Direct3D 11 教程7:纹理映射和常量缓冲区...
查看>>
Objective C内存管理进阶(一):实践准则
查看>>
TrackPoint_configure_ThinkPad_squeeze(06-16.2011)
查看>>
CSDN博客频道“移动开发之我见”主题征文活动
查看>>
PHPExcel常用方法汇总
查看>>
用户登陆的业务流程架构设计
查看>>
创建表的备份和删除
查看>>
HTML data属性
查看>>
Java 第一个程序 HelloWorld!
查看>>
weblogic.cluster.MulticastMonitor, monitoring multicast traffic in a Weblogic Cluster
查看>>
android 通过修改图片像素实现CircleImageView
查看>>