使用数据OnClick Recyclerview到新的Recyclerview活动

时间:2016-11-30 05:33:37

标签: android android-recyclerview

我仍然坚持这个问题。我有一个类似下面的活动,想要制作

enter image description here

enter image description here

我想将数据(标题名称,图像和描述)发送到新的recyclerview活动。我仍然无法实现我的代码,我已阅读this但我仍然不知道。

这是我的代码:

Child_Tab1.java

public class Child_Tab1 extends Activity {

List<GetDataAdapter> GetDataAdapter1;
RecyclerView recyclerView;
RecyclerView.LayoutManager recyclerViewlayaoutManager;
RecyclerView.Adapter recyclerViewadapter;
String GET_JSON_DATA_HTTP_URL = "http://www.kinandayu.com/image_content/getAllImage.php";
String JSON_IMAGE_TITLE_NAME = "name";
String JSON_IMAGE_URL = "image";

JsonArrayRequest jsonArrayRequest;
RequestQueue requestQueue;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.child_tab_1);
GetDataAdapter1 = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.rv1);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
SpacesItemsDecoration decoration = new SpacesItemsDecoration(4);
recyclerView.addItemDecoration(decoration);

JSON_DATA_WEB_CALL();
}

private void JSON_DATA_WEB_CALL() {
jsonArrayRequest = new JsonArrayRequest(GET_JSON_DATA_HTTP_URL, new Response.Listener<JSONArray>() {
    @Override
    public void onResponse (JSONArray response) {
        JSON_PARSE_DATA_AFTER_WEBCALL(response);
    }
},
new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

    }
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}

public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array) {
for (int i = 0; i<array.length(); i++) {
    GetDataAdapter GetDataAdapter2 = new GetDataAdapter();
    JSONObject json = null;
    try {
        json = array.getJSONObject(i);
          GetDataAdapter2.setImageTitleNamee(json.getString(JSON_IMAGE_TITLE_NAME));
        GetDataAdapter2.setImageServerUrl("http://" + json.getString(JSON_IMAGE_URL));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    GetDataAdapter1.add(GetDataAdapter2);
}
    recyclerViewadapter = new RecyclerViewAdapter(GetDataAdapter1, this);
    recyclerView.setAdapter(recyclerViewadapter);
   }
}

这是RecyclerViewAdapter.java

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

Context context;
List<GetDataAdapter> getDataAdapter;
ImageLoader imageLoader1;

public RecyclerViewAdapter(List<GetDataAdapter> getDataAdapter, Context context){

    super();
    this.getDataAdapter = getDataAdapter;
    this.context = context;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent,false);
    ViewHolder viewHolder = new ViewHolder(v);

    return viewHolder;
}

@Override
public void onBindViewHolder(ViewHolder Viewholder, int position) {
    GetDataAdapter getDataAdapter1 = getDataAdapter.get(position);
    imageLoader1 = ServerImageParseAdapter.getInstance(context).getImageLoader();
    imageLoader1.get(getDataAdapter1.getImageServerUrl(), ImageLoader.getImageListener
            (Viewholder.networkImageView, R.drawable.placeholder, android.R.drawable.ic_dialog_alert
            ));
    Viewholder.networkImageView.setImageUrl(getDataAdapter1.getImageServerUrl(), imageLoader1);
     Viewholder.ImageTitleNameView.setText(getDataAdapter1.getImageTitleName());
}

@Override
public int getItemCount() {
    return getDataAdapter.size();
}

class ViewHolder extends RecyclerView.ViewHolder {
    public TextView ImageTitleNameView;
    public NetworkImageView networkImageView;

    public ViewHolder(View itemView) {
        super(itemView);
        ImageTitleNameView = (TextView) itemView.findViewById(R.id.textView_item);
        networkImageView = (NetworkImageView) itemView.findViewById(R.id.VollyNetworkImageView1);
}
}
}

我认为这很简单但我不确切知道代码以及Tom如何实现它。 Maye有人可以帮我处理我的代码。每个答案对我都很有帮助。提前致谢

0 个答案:

没有答案