2016-05-29 10 views
0

ボタンをクリックすると、リストに保存されているデータをアクティビティに送信する必要があります。そのアクティビティにはリストがあり、リストには送信されたデータが表示されます前の活動から私がこれまで行ってきたことは次のとおりです: -他のアクティビティにリストを送信できません

ActivityOneでは私はデータを解析し、リストビューでデータを設定しました。これには、JSONArrayがあるシナリオがあります。私はそれをListに格納し、その特定のObjectのすべてのデータを取得しました。しかし、ボタンをクリックすると、他のアクティビティにリストを送ることはできません。 は、ここに私のコードです: -

pDialog = new ProgressDialog(getActivity()); 
     pDialog.setMessage("Loading...Please Wait..."); 
     pDialog.setCancelable(false); 
     pDialog.show(); 

     Volley.newRequestQueue(getActivity()).add(new JsonObjectRequest(Request.Method.GET, url, new Response.Listener<JSONObject>() { 
      @Override 
      public void onResponse(JSONObject response) { 
       hidePDialog(); 
       try { 
        JSONObject result = response.getJSONObject("result"); 
        JSONArray jsonArray = result.getJSONArray("course"); 

        System.out.println("Course: == >" + result.getJSONArray("course")); 
        for (int i = 0; i < jsonArray.length(); i++) { 
         JSONObject trainingObj = jsonArray.getJSONObject(i); 
         movie = new Movie(); 
         movie.setCourse_id(trainingObj.getString("course_id")); 
         movie.setParent_course_id(trainingObj.getString("parent_course_id")); 
         movie.setCourse_name(trainingObj.getString("course_name")); 
         movie.setCourse_price(trainingObj.getString("course_price")); 
         movie.setCourse_price_dollar(trainingObj.getString("course_price_doller")); 
         movie.setCourse_price_discount_dollar(trainingObj.getString("course_price_discunt_doller")); 
         movie.setCourse_discount_date(trainingObj.getString("course_discunt_date")); 
         movie.setCourse_description(trainingObj.getString("course_description")); 
         movie.setCourse_image(trainingObj.getString("course_image")); 


//      module = trainingObj.getJSONArray("module"); 
//      jsonArray = module.toString(); 
         List<Module> mod1=new ArrayList<Module>(); 

         JSONArray module = trainingObj.getJSONArray("module"); 
         for (int j = 0; j < module.length(); j++) { 
          JSONObject moduleObj = module.getJSONObject(j); 
          modl=new Module(); 
          modl.setModule_id(moduleObj.getString("module_id")); 
          modl.setVideo_price(moduleObj.getString("video_price")); 
          modl.setVideo_price_doller(moduleObj.getString("video_price_doller")); 
          modl.setVideo_price_discunt(moduleObj.getString("video_price_discunt")); 
          modl.setVideo_price_discunt_doller(moduleObj.getString("video_price_discunt_doller")); 
          modl.setVideo_discunt_date(moduleObj.getString("video_discunt_date")); 
          modl.setVideo_type(moduleObj.getString("video_type")); 
          modl.setVideo_link(moduleObj.getString("video_link")); 
          modl.setVideo_image(moduleObj.getString("video_image")); 
          modl.setVideo_description(moduleObj.getString("video_description")); 
          mod1.add(j,modl); 

         } 
         movie.setModulelist(mod1); 



         trainingList.add(movie); 

すべてのデータはsetModuleList内に保存されています。今すぐボタンをクリックしてアダプタから私は別のアクティビティにデータを送信する必要があります。しかし、私はそれを行うことができません。

btn_view_module.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 



       Intent in = new Intent(activity, ViewModule.class); 

       activity.startActivity(in); 

      } 
     }); 

はシングルトンクラスを以下に示す: -

import java.util.List; 

/** 
* Created by Administrator on 2/9/2016. 
*/ 

public class Movie { 
    private String course_id; 
    private String parent_course_id; 
    private String course_name; 
    private String course_price; 
    private String course_price_dollar; 
    private String course_price_discount_dollar; 
    private String course_discount_date; 
    private String course_description; 
    private String course_image; 
    private String total_module; 
    // Module 
    private String module_id; 
    private String video_price; 
    private String video_price_doller; 
    private String video_price_discunt; 
    private String video_price_discunt_doller; 
    private String video_discunt_date; 
    private String video_type; 
    private String video_link; 
    private String video_image; 
    private String video_description; 
    private List<Module> modulelist; 


    public Movie() { 
    } 

    public Movie(String course_id, String parent_course_id, String course_name, String course_price, 
       String course_price_dollar, String course_price_discount_dollar, String course_discount_date, 
       String course_description, String course_image, String total_module, String module_id, 
       String video_price, String video_price_doller, String video_price_discunt, 
       String video_price_discunt_doller, String video_discunt_date, String video_type, 
       String video_link, String video_image, String video_description) { 
     this.course_id = course_id; 
     this.parent_course_id = parent_course_id; 
     this.course_name = course_name; 
     this.course_price = course_price; 
     this.course_price_dollar = course_price_dollar; 
     this.course_price_discount_dollar = course_price_discount_dollar; 
     this.course_discount_date = course_discount_date; 
     this.course_description = course_description; 
     this.course_image = course_image; 
     this.total_module = total_module; 
     this.module_id = module_id; 
     this.video_price = video_price; 
     this.video_price_doller = video_price_doller; 
     this.video_price_discunt = video_price_discunt; 
     this.video_price_discunt_doller = video_price_discunt_doller; 
     this.video_discunt_date = video_discunt_date; 
     this.video_type = video_type; 
     this.video_link = video_link; 
     this.video_image = video_image; 
     this.video_description = video_description; 
    } 

    public String getCourse_id() { 
     return course_id; 
    } 

    public void setCourse_id(String course_id) { 
     this.course_id = course_id; 
    } 

    public String getParent_course_id() { 
     return parent_course_id; 
    } 

    public void setParent_course_id(String parent_course_id) { 
     this.parent_course_id = parent_course_id; 
    } 

    public String getCourse_name() { 
     return course_name; 
    } 

    public void setCourse_name(String course_name) { 
     this.course_name = course_name; 
    } 

    public String getCourse_price() { 
     return course_price; 
    } 

    public void setCourse_price(String course_price) { 
     this.course_price = course_price; 
    } 

    public String getCourse_price_dollar() { 
     return course_price_dollar; 
    } 

    public void setCourse_price_dollar(String course_price_dollar) { 
     this.course_price_dollar = course_price_dollar; 
    } 

    public String getCourse_price_discount_dollar() { 
     return course_price_discount_dollar; 
    } 

    public void setCourse_price_discount_dollar(String course_price_discount_dollar) { 
     this.course_price_discount_dollar = course_price_discount_dollar; 
    } 

    public String getCourse_discount_date() { 
     return course_discount_date; 
    } 

    public void setCourse_discount_date(String course_discount_date) { 
     this.course_discount_date = course_discount_date; 
    } 

    public String getCourse_description() { 
     return course_description; 
    } 

    public void setCourse_description(String course_description) { 
     this.course_description = course_description; 
    } 

    public String getCourse_image() { 
     return course_image; 
    } 

    public void setCourse_image(String course_image) { 
     this.course_image = course_image; 
    } 

    public String getTotal_module() { 
     return total_module; 
    } 

    public void setTotal_module(String total_module) { 
     this.total_module = total_module; 
    } 

    public String getModule_id() { 
     return module_id; 
    } 

    public void setModule_id(String module_id) { 
     this.module_id = module_id; 
    } 

    public String getVideo_price() { 
     return video_price; 
    } 

    public void setVideo_price(String video_price) { 
     this.video_price = video_price; 
    } 

    public String getVideo_price_doller() { 
     return video_price_doller; 
    } 

    public void setVideo_price_doller(String video_price_doller) { 
     this.video_price_doller = video_price_doller; 
    } 

    public String getVideo_price_discunt() { 
     return video_price_discunt; 
    } 

    public void setVideo_price_discunt(String video_price_discunt) { 
     this.video_price_discunt = video_price_discunt; 
    } 

    public String getVideo_price_discunt_doller() { 
     return video_price_discunt_doller; 
    } 

    public void setVideo_price_discunt_doller(String video_price_discunt_doller) { 
     this.video_price_discunt_doller = video_price_discunt_doller; 
    } 

    public String getVideo_discunt_date() { 
     return video_discunt_date; 
    } 

    public void setVideo_discunt_date(String video_discunt_date) { 
     this.video_discunt_date = video_discunt_date; 
    } 

    public String getVideo_type() { 
     return video_type; 
    } 

    public void setVideo_type(String video_type) { 
     this.video_type = video_type; 
    } 

    public String getVideo_link() { 
     return video_link; 
    } 

    public void setVideo_link(String video_link) { 
     this.video_link = video_link; 
    } 

    public String getVideo_image() { 
     return video_image; 
    } 

    public void setVideo_image(String video_image) { 
     this.video_image = video_image; 
    } 

    public String getVideo_description() { 
     return video_description; 
    } 

    public void setVideo_description(String video_description) { 
     this.video_description = video_description; 
    } 

    public List<Module> getModulelist() { 
     return modulelist; 
    } 

    public void setModulelist(List<Module> modulelist) { 
     this.modulelist = modulelist; 
    } 
} 

Module.java

public class Module { 

    private String module_id; 
    private String video_price; 
    private String video_price_doller; 
    private String video_price_discunt; 
    private String video_price_discunt_doller; 
    private String video_discunt_date; 
    private String video_type; 
    private String video_link; 
    private String video_image; 
    private String video_description; 

    public Module() { 
    } 

    public Module(String module_id,String video_price, String video_price_doller, String video_price_discunt, 
        String video_price_discunt_doller, String video_discunt_date, String video_type, 
        String video_link, String video_image, String video_description){ 
     this.module_id = module_id; 
     this.video_price = video_price; 
     this.video_price_doller = video_price_doller; 
     this.video_price_discunt = video_price_discunt; 
     this.video_price_discunt_doller = video_price_discunt_doller; 
     this.video_discunt_date = video_discunt_date; 
     this.video_type = video_type; 
     this.video_link = video_link; 
     this.video_image = video_image; 
     this.video_description = video_description; 
    } 

    public String getVideo_description() { 
     return video_description; 
    } 

    public void setVideo_description(String video_description) { 
     this.video_description = video_description; 
    } 

    public String getModule_id() { 
     return module_id; 
    } 

    public void setModule_id(String module_id) { 
     this.module_id = module_id; 
    } 

    public String getVideo_price() { 
     return video_price; 
    } 

    public void setVideo_price(String video_price) { 
     this.video_price = video_price; 
    } 

    public String getVideo_price_doller() { 
     return video_price_doller; 
    } 

    public void setVideo_price_doller(String video_price_doller) { 
     this.video_price_doller = video_price_doller; 
    } 

    public String getVideo_price_discunt() { 
     return video_price_discunt; 
    } 

    public void setVideo_price_discunt(String video_price_discunt) { 
     this.video_price_discunt = video_price_discunt; 
    } 

    public String getVideo_price_discunt_doller() { 
     return video_price_discunt_doller; 
    } 

    public void setVideo_price_discunt_doller(String video_price_discunt_doller) { 
     this.video_price_discunt_doller = video_price_discunt_doller; 
    } 

    public String getVideo_discunt_date() { 
     return video_discunt_date; 
    } 

    public void setVideo_discunt_date(String video_discunt_date) { 
     this.video_discunt_date = video_discunt_date; 
    } 

    public String getVideo_type() { 
     return video_type; 
    } 

    public void setVideo_type(String video_type) { 
     this.video_type = video_type; 
    } 

    public String getVideo_link() { 
     return video_link; 
    } 

    public void setVideo_link(String video_link) { 
     this.video_link = video_link; 
    } 

    public String getVideo_image() { 
     return video_image; 
    } 

    public void setVideo_image(String video_image) { 
     this.video_image = video_image; 
    } 

をサンプルJSONを以下に提供する: -

"course": [{ 
      "course_id": "3", 
      "parent_course_id": "0", 
      "course_name": "PRINCE2 (Foundation and Practitioner)", 
      "course_price": "24000", 
      "course_price_doller": "140", 
      "course_price_discunt": "22000", 
      "course_price_discunt_doller": "220", 
      "course_discunt_date": "2016-04-04", 
      "course_description": "We are an expert training organization with our faculty having vast experience in consulting and training accredited by Peoplecert on behalf of Axelos.\r\nThis program is for 3 full days.\r\n\r\nXellentro has one of the best Project Management Professionals with large experience of project management training and consulting in this subject across the globe.", 
      "course_image": "http:\/\/arrisofttech.com\/2016\/xellentroapp\/assets\/uploads\/course\/SL571531558C660_COURSE_228x80.png", 
      "total_module": 3, 
      "module": [{ 
       "module_id": "14", 
       "video_price": "12", 
       "video_price_doller": "11", 
       "video_price_discunt": "123", 
       "video_price_discunt_doller": "12", 
       "video_discunt_date": "2016-02-03", 
       "video_type": "1", 
       "video_link": "arrisofttech.com\/2016\/xellentroapp\/video\/sample_2.mp4", 
       "video_image": "http:\/\/arrisofttech.com\/2016\/xellentroapp\/assets\/uploads\/course\/SL571531558C660_COURSE_228x80.png", 
       "video_description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." 
      }, { 
       "module_id": "12", 
       "video_price": "12", 
       "video_price_doller": "11", 
       "video_price_discunt": "123", 
       "video_price_discunt_doller": "12", 
       "video_discunt_date": "2016-02-03", 
       "video_type": "0", 
       "video_link": "https:\/\/www.youtube.com\/watch?v=QSaWoca3SjY&list=RDQSaWoca3SjY", 
       "video_image": "http:\/\/arrisofttech.com\/2016\/xellentroapp\/assets\/uploads\/course\/SL571531558C660_COURSE_228x80.png", 
       "video_description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." 
      }, { 
       "module_id": "13", 
       "video_price": "12", 
       "video_price_doller": "11", 
       "video_price_discunt": "123", 
       "video_price_discunt_doller": "12", 
       "video_discunt_date": "2016-02-03", 
       "video_type": "0", 
       "video_link": "https:\/\/www.youtube.com\/watch?v=QSaWoca3SjY&list=RDQSaWoca3SjY", 
       "video_image": "http:\/\/arrisofttech.com\/2016\/xellentroapp\/assets\/uploads\/course\/SL571531558C660_COURSE_228x80.png", 
       "video_description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." 
      }] 

私を助けてください。

答えて

0

あなたのアクティビティにあるリストを新しいアクティビティに直接送信することはできません。 thisメソッドを使用して、活動内の限られた量のデータを送信することができます。

これが困難な場合は、シングルトンオブジェクトを使用して変数を共有することもできます。

+0

私はシングルトンオブジェクトを使用しています。コードを更新し、シングルトンクラスであなたを共有させてください。 –

+0

私はコントロールを使用することができません。これを克服するために何をすべきか教えてください –

0

クラスをシリアライズ可能にする。 E型がSerializableの場合、ArrayListを渡すことができます。

intent.putExtra("modulelist", setModuleList); 

をし、他のアクティビティの使用にそれを得るために:使用しています

ArrayList<String> moduleList = (ArrayList<String>) getIntent().getSerializableExtra("modulelist"); 

チェックこのout

+0

私はコードを更新しました。見て、私に何をすべきか教えてください。 –

+0

は基本的にあなたのモジュールクラスをシリアライズ可能に実装します –

0

シングルトンでパブリックコンストラクタを取り出し、プライベートコンストラクタに置き換えます。次に、静的なgetInstance()メソッドを次のように追加します。

static Module instance = null;//Declare instance variable 
private Module(){ 

} 

public static Module getInstance(){ 

if(instance != null){ 
    return instance; 
} 
else{ 

instance = new Module(); 
    return instance; 
} 

} 

ここで、他の場所からあなたのインスタンスを保持するために次のコマンドを使用します。

Module singletonModule = Module.getInstance(); 

これで、インスタンスに対して任意のメソッドを実行できます。

+0

私はそれを得ることができません。あなたはそれを説明してもらえますか? –

関連する問題