将ArrayList从Adapter传递给Button上的Activity Click

时间:2017-01-13 15:53:39

标签: android listview arraylist serializable android-bundle

我需要一些帮助,我已经查看了其他问题,但找不到合适的解决方案,我想显示一个列表(RecyclerView)来自适配器List on Item点击发送包信息。 (列表填充第一个列表的项目点击上的另一个列表)
以下是我遇到的代码,

这是来自ArrayList中的FirstActivity Parsing Json

,"Not Found")

这是模型类

JSONArray complainJsonArray= jsonObj.getJSONArray("complains");
                                ArrayList<MaintanceModel.UserComplain> listdata = new ArrayList<MaintanceModel.UserComplain>();
                                for (int k = 0; k<complainJsonArray.length(); k++){
                                    JSONObject complainJObject = complainJsonArray.getJSONObject(k);
                                    listdata.add(new MaintanceModel.UserComplain(Integer.parseInt(complainJObject.getString("id"))
                                            ,complainJObject.getString("description")
                                            ,complainJObject.getString("created_at")));
                                }
MaintanceModel maintanceModel = new MaintanceModel();
maintanceModel.setComplains(listdata);
maintanceModelArrayList.add(maintanceModel);

这是Click On Clickle Pass

     public class MaintanceModel implements Serializable{ 
               private ArrayList<UserComplain> complains;

         public MaintanceModel() {
            }
         public ArrayList<UserComplain> getComplains() {
            return complains;
        }

        public void setComplains(ArrayList<UserComplain> complains) {
            this.complains = complains;
        }

    public MaintanceModel (String mainRefNum, ArrayList<UserComplain> complains){
    this.complains=complains;
    this.mainRefNum = mainRefNum;
            }

     public static class UserComplain{

            public final String complainDescr,complaiCreateDate;
            public final int complainId;

            public UserComplain(int complainId, String complainDescr, String complaiCreateDate){

                this.complainId=complainId;
                this.complainDescr=complainDescr;
                this.complaiCreateDate=complaiCreateDate;
            }
}

此详细活动接收结束

public class MaintenanceAdapter extends RecyclerView.Adapter<MaintenanceAdapter.ViewHolder>  {
    private Context mContext;
    List<MaintanceModel> maintanceModelList = new ArrayList<MaintanceModel>();
    public MaintenanceAdapter(Context mContext, ArrayList<MaintanceModel> items) {
        this.mContext = mContext;
        maintanceModelList = items;
    }
public void onBindViewHolder(final ViewHolder holder, final int position) {
        final MaintanceModel maintanceModel= maintanceModelList.get(position);

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

                 Bundle bundle = new Bundle();
                    bundle.putString("Ref_ID",maintanceModelList.get(position).getMainRefNum());
                    bundle.putString("Customer_Name",maintanceModelList.get(position).getMainUserName());
                    bundle.putString("Created_Date",maintanceModelList.get(position).getMainCreateDate());
                    bundle.putSerializable("ARRAYLIST",maintanceModelList.get(position).getComplains());


                    Intent itemClick = new Intent(mContext, MaintenanceDetail.class);
                    itemClick.putExtras(bundle);
                      itemClick.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    itemClick.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                     itemClick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mContext.startActivity(itemClick);

                }

        });

}

这是崩溃日志

public class MaintenanceDetail extends AppCompatActivity {
List<MaintanceModel> maintanceModelList;


protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maintenance_detail);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        Intent intent = this.getIntent();
        Bundle bundle = intent.getExtras();
String refarnceNumber = getIntent().getExtras().getString("Ref_ID");

 List<MaintanceModel> complainList = (List<MaintanceModel>)bundle.getSerializable("ARRAYLIST");  <<< Here I want to received the list items and then set in to adapter 

}

0 个答案:

没有答案