zoukankan      html  css  js  c++  java
  • Click ListView Item跳转Activity

    今天学习了ListView点击Item跳转,修改上一篇代码bindData方法

    lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    // TODO Auto-generated method stub
                    ListView listView = (ListView)arg0;
                    HashMap<String, String> map = (HashMap<String, String>)listView.getItemAtPosition(arg2);
                    String id = map.get("id");
                    
                    Bundle bundle = new Bundle(); //bundle可以添加多个参数
                    bundle.putString("id", id);
                    //bundle.putString("info", "info"); 
                    Intent intent = new Intent(MainActivity.this, LifeCycleActivity.class); //create intent object
                    //intent.putExtra("id",id);  //parma
                    intent.putExtras(bundle); //params
                    MainActivity.this.startActivity(intent);  //start activity
                }
            });        

    添加activitylifecycle.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
    
     <Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button" />
      
    </LinearLayout>

    添加activity类:LifeCycleActivity

    public final String TAG="Actity:";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activitylifecycle);
            Log.d(TAG, "------onCreate------");
            //get params
            Bundle bundle = this.getIntent().getExtras();
            String id = bundle.getString("id");
            Log.e("params:", "--------------------:"+id+"----------------");
            
            Button btn = (Button)findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {
                
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent();
                    intent.setClass(LifeCycleActivity.this, MainActivity.class);
                    startActivity(intent);
                    LifeCycleActivity.this.finish();
                }
            });
        }

    跳转到LifeCycleActivity 见下面效果

    上面即点击ListView点击Item跳转.

  • 相关阅读:
    Java设计模式之单例模式
    sql查询优化整理
    MYSQL 调优学习笔记
    记一次失败的大厂面试
    ElasticSearch 6.3.2 整合 Springboot 2.1.10.RELEASE 版本,使用 Logstash 导入 mysql 数据
    ajax技术实现登录判断用户名是否重复以及利用xml实现二级下拉框联动
    浅谈 KMP 算法
    转载:Docker入门只需看这一篇就够了
    Spring Boot 监听 Activemq 中的特定 topic ,并将数据通过 RabbitMq 发布出去
    hadoop入门之海量Web日志分析 用Hadoop提取KPI统计指标
  • 原文地址:https://www.cnblogs.com/mlgblog/p/3419992.html
Copyright © 2011-2022 走看看