how to get Hash table Arraylist to other intent?

前端 未结 4 1068
Happy的楠姐
Happy的楠姐 2020-12-10 00:21

I have hashtbles in array list.

 List> info = new ArrayList>();


 Hashtable<         


        
相关标签:
4条回答
  • 2020-12-10 00:45

    Convert your Hashtables to Bundles, and pass the Bundles using intent.putExtra()

    0 讨论(0)
  • 2020-12-10 00:48

    Convert your Hashtables to Bundles, and pass the Bundles using intent.putExtra() here 's the example

    Intent i = new Intent(this,yourclass.class);

    i.putExtra("info",info);

    and you can get the values in other intent

    Bundle extra=getIntent().getExtras();

    extra.geStrinf("info");

    0 讨论(0)
  • 2020-12-10 00:51
    List<Hashtable<String, String>> info = new ArrayList<Hashtable<String, String>>(); 
    String[] selItemArray = new String[info .size()];
                //copy your List of Hashtable Strings into the Array ,and then pass it in your intent
                // ....
                Intent intent = new Intent(InfoClass.this, AnotherClass.class);
                intent.putExtra("info_array", selItemArray);
                startActivityForResult(intent, 0);  
    

    type of arraylist

    putIntegerArrayListExtra(String name, ArrayList<Integer> value)
    
            putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
    
            putStringArrayListExtra(String name, ArrayList<String> value)
    
            putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value)
    
        Then you can read from you next activity by replacing put with get with key string as argument,eg
    
    myIntent.getStringArrayListExtra("key");
    

    Array :

    Bundle b=new Bundle();
    b.putStringArray(key, new String[]{value1, value2});
    Intent i=new Intent(context, Class);
    i.putExtras(b);
    
    
    
    In order to read:
    
    Bundle b=this.getIntent().getExtras();
    String[] array=b.getStringArray(key);
    

    Hope this will help you.

    Refer : Passing a list of objects between Activities

    0 讨论(0)
  • 2020-12-10 01:01

    Create a class that extends Serializable with getter setter for the List<Hashtable<String, String>> list

    Custom.java

    public class Custom implements Serializable{
    
        private static final long serialVersionUID = 4466821913603037341L;
        private List<Hashtable<String, String>> list;
    
    
        public List<Hashtable<String, String>> getList() {
            return list;
        }
    
        public void setList(List<Hashtable<String, String>> list) {
            this.list = list;
        }
    }
    

    To pass to next Activity.

    List<Hashtable<String, String>> list = new ArrayList<Hashtable<String,String>>();
    
    Custom custom = new Custom();
    custom.setList(list);
    intent.putExtra("myobj", custom);
    

    To retrieve in next Activity

    Intent intent = getIntent();
    Custom custom = (Custom) intent.getSerializableExtra("myobj");
    List<Hashtable<String, String>> list = custom.getList();
    
    0 讨论(0)
提交回复
热议问题