android捕獲ListView中每個item點擊事件

來源:互聯網
上載者:User

標籤:android   class   blog   code   java   http   

轉自:http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.