将列表项名称从片段传递到活动

时间:2016-07-01 06:31:49

标签: android listview android-fragments android-activity

我有一个回收站视图列表项,我在数组列表中发送静态数据并尝试将listitem的名称提供给下一个活动

Homepageactivity -inside(片段列表视图项) - > (项目名称)活动

我想将文本1发送给另一个活动 这是我的片段

public class SomeFragment extends Fragment {
 //.. body

    private ArrayList<DataObject> getDataSet() {
        ArrayList results = new ArrayList<DataObject>();
        for (int index = 0; index < 20; index++) {

            DataObject sr1 = new DataObject("Test",
                    "fsdf", "dfsd", "fdgdd","sdfsdfs","dfasdf");
            sr1.setmText1(" fdfgd");

            sr1.setmText2("vgsdfgsdfgg");
            sr1.setmText3("gdfgf ");
            sr1.setmText6("gfdfgd");
            sr1.setmText4("dfgdfg ");
            sr1.setmText5 ("S1");
            results.add(sr1);

            DataObject sr2 = new DataObject("Test",
                    "fsdf", "dfsd", "fdgdd","sdfsdfs","dfasdf");
            sr2.setmText1("dfadfasd");
            sr2.setmText2("dfasdf");
            sr2.setmText3("dfasfs");
            sr2.setmText6("sdfsff");
            sr2.setmText4("fsdf");
            sr2.setmText5("S1,S2");
            results.add(sr2);
            // and so on 

        }
        return results;
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个

<强> Activity1.java

  

Intent intent = new Intent(Activity1.this,Activity2.class);

     

intent.putExtra(&#34; myData&#34;,arraylisttosen);

     

startActivity(意向);

<强> Activity2.java

  

ArrayList myList =(ArrayList)   。getIntent()getSerializableExtra(&#34; myData的&#34);