前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android的listview item点击详解

android的listview item点击详解

作者头像
xiangzhihong
发布2018-01-26 19:31:45
6510
发布2018-01-26 19:31:45
举报
文章被收录于专栏:向治洪向治洪

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

}

}

});

}

}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-01-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档