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

前端 未结 3 725
滥情空心
滥情空心 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:30

    create array list like this

        public ArrayList Id = new ArrayList();
    public  ArrayList Name = new ArrayList();
       public  ArrayList Gender= new ArrayList();
    
    
         for (int i = 0; i < jsonArray.length(); i++) {
             JSONObject objJson = jsonArray.getJSONObject(i);
    
                    // here you can get id,name,city...
    
              Id.add(objJson.getInt("id"));
    
             Name.add(objJson.getString("name")); 
             Gender.add(objJson.getString("Gender"));
    
    
    
    
     //You need to use this code in the class where you have the view , 
    
    // list item click 
         List_View.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
                        @Override
                        public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
                            // TODO Auto-generated method stub
    
    
    
            Intent i = new Intent(this, abc.class); 
    // here arg2 is argument of onitemclick method
    // this will pick the same item from array list that is clicked on list view 
                    i.putExtra("key_name" , Id.get(arg2));
                    i.putExtra("key_name" , Name.get(arg2));
                    i.putExtra("key_name" , Gender.get(arg2));
    
                    startActivity(i);       
    
    
                    }
    
    
    
    
                    });
    

    can see this also

    http://www.ezzylearning.com/tutorial.aspx?tid=1351248

    and

    http://www.bogotobogo.com/Android/android6ListViewSpinnerGridViewGallery.php

提交回复
热议问题