android捕获ListView中每个item点击事件
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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(yout.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,yout.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);
}
}
});
}
}。