Click ListView Item跳转Activity_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > Click ListView Item跳转Activity

Click ListView Item跳转Activity

 2013/11/12 18:45:16  一米,希望  博客园  我要评论(0)
  • 摘要:今天学习了ListView点击Item跳转,修改上一篇代码bindData方法lv.setOnItemClickListener(newOnItemClickListener(){publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,intarg2,longarg3){//TODOAuto-generatedmethodstubListViewlistView=(ListView)arg0;HashMap<String
  • 标签:view list 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跳转.

 

发表评论
用户名: 匿名