Android captures each item click event in a ListView

Source: Internet
Author: User

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

Android captures each item click event in a ListView

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.