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);
}
}
});
}
}
最后更新:2017-04-03 12:54:02
上一篇:
linux驱动开发--copy_to_user 、copy_from_user函数实现内核空间数据与用户空间数据的相互访问
下一篇:
Android 通过包名打开App的代码
Ubuntu linux解决:”修改profile/enviroment文件无法进入ubuntu“的方法
《JVM故障诊断指南》之3 —— Java 线程: JVM持有内存的分析
ORACLE 官方文档
Oracle 12c ASM 防范异常的恢复增强
对安卓系统的功能性升级来说,安全补丁更重要!
道旅鬼谷子分享:如何打好业务监控的组合拳
Java多线程问题总结(下)
C# WinForm多线程开发(二) ThreadPool 与 Timer
捡到iPhone7怎么解锁?苹果6splus解锁密码忘记导致手机被锁定该怎么办
《8051系列单片机C程序设计完全手册》的电子书PDF完整合集版