当前位置: 移动技术网 > IT编程>移动开发>Android > android开发之捕获ListView中每个item点击事件(代码实例)

android开发之捕获ListView中每个item点击事件(代码实例)

2018年12月09日  | 移动技术网IT编程  | 我要评论

忆豆香,流行服饰图片,最言情小说网

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(r.layout.main);
        mylistview = (listview)findviewbyid(r.id.listview);
        list.add(&quot;linearlayout&quot;);
        list.add(&quot;absolutelayout&quot;);
        list.add(&quot;tablelayout&quot;);
        list.add(&quot;relativelayout&quot;);
        list.add(&quot;framelayout&quot;);
        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(&quot;linearlayout&quot;))
                {
                    intent intent = new intent(&quot;com.wps.android.linearlayout&quot;);
                    startactivity(intent);
                }
                if(list.get(arg2).equals(&quot;absolutelayout&quot;))
                {
                    intent intent = new intent(&quot;com.wps.android.absolutelayout&quot;);
                    startactivity(intent);
                }
                if(list.get(arg2).equals(&quot;tablelayout&quot;))
                {
                    intent intent = new intent(&quot;com.wps.android.tablelayout&quot;);
                    startactivity(intent);
                }
                if(list.get(arg2).equals(&quot;relativelayout&quot;))
                {
                    intent intent = new intent(&quot;com.wps.android.relativelayout&quot;);
                    startactivity(intent);
                }
                if(list.get(arg2).equals(&quot;framelayout&quot;))
                {
                    intent intent = new intent(&quot;com.wps.android.framelayout&quot;);
                    startactivity(intent);
                }
            }
             
        });
    }
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网