How to start a new activity form ListView and give it multiple parameters

前端 未结 3 728
滥情空心
滥情空心 2021-01-16 15:25

Below is my code which displays data in listview which is parses from json.
I want to start new activity when the user clicks on any item in the list.

I followe

3条回答
  •  爱一瞬间的悲伤
    2021-01-16 16:21

    You start an activty with startActivity(intent);

    You set the OnClickListner on your ListView which is not included in your code so Im implying:

    OnItemClickListener listener = new OnItemClickListener (){
    
      @Override
      onItemClick(AdapterView parent, View view, int position, long id){
          String name = ((TextView) view.findViewById(R.id.txtText)).getText();
          Intent intent = new Intent(context,WhatEverYouWant.class);
          intent.putExtra("name",name);
          startActivity(intent);
      }
    
    }
    
    ListView listView = getView().findViewById(R.id.listview);
    listView.setOnItemClickListener (listener);
    

提交回复
热议问题