您当前的位置: 首页 >  android

xiangzhihong8

暂无认证

  • 3浏览

    0关注

    1324博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

android的listview item点击详解

xiangzhihong8 发布时间:2014-01-02 18:02:44 ,浏览量:3

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 list = new ArrayList();
     @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 myArrayAdapter = new ArrayAdapter
                             ( 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);
                 }
             }
             
         });
     }
}
关注
打赏
1482932726
查看更多评论
立即登录/注册

微信扫码登录

0.0415s