本文主要是介绍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 stubListView 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); //parmaintent.putExtras(bundle); //paramsMainActivity.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" ><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button" /></LinearLayout>
添加activity类:LifeCycleActivity
public final String TAG="Actity:";@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activitylifecycle);Log.d(TAG, "------onCreate------");//get paramsBundle 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 stubIntent intent = new Intent();intent.setClass(LifeCycleActivity.this, MainActivity.class);startActivity(intent);LifeCycleActivity.this.finish();}});}
这篇关于Click ListView Item跳转Activity的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!