【问题标题】:How putExtra in RecyclerView with arraylist from JSON如何在 RecyclerView 中使用来自 JSON 的数组列表 putExtra
【发布时间】:2018-06-27 13:40:04
【问题描述】:

我正在尝试从具有确定位置的 RecyclerView 进行另一个活动,并且我需要 putExtra 以获取 destin 活动中的加载信息。

我是基于这个例子,但是我在调​​用 JSON 文件时遇到了问题。

示例代码是这样的:

JsonObjectRequest jreq = new JsonObjectRequest(Request.Method.GET, url,
                new com.android.volley.Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            int success = response.getInt("success");

                            if (success == 1) {
                                JSONArray ja = response.getJSONArray("infoRecy");

                                for (int i = 0; i < ja.length(); i++) {

                                    JSONObject jobj = ja.getJSONObject(i);
                                    HashMap<String, String> item = new HashMap<String, String>();
                                    // item.put(ITEM_ID, jobj.getString(ITEM_ID));
                                    item.put(ITEM_RUTA,
                                            jobj.getString(ITEM_RUTA));
                                    item.put(ITEM_VEH,
                                            jobj.getString(ITEM_VEH));

                                    Item_List.add(item);

                                } // for loop ends

                                String[] from = {ITEM_RUTA, ITEM_VEH};
                                int[] to = {R.id.i_ruta, R.id.i_veh};

                                adapter = new SimpleAdapter(
                                        getApplicationContext(), Item_List,
                                        R.layout.message_list_row, from, to);

                                listview.setAdapter(adapter);
                                listview.setOnItemClickListener(new ListitemClickListener());



                            } // if ends

                        } catch (JSONException e) {…

我在这行有问题,我不知道如何修复

listview.setOnItemClickListener(new ListitemClickListener());

显示这个错误: 无法解析符号“ListitemClickListener”

因为我的点击方式不同

   @Override
    public void onMessageRowClicked (int i) {
        // verify whether action mode is enabled or not
        // if enabled, change the row state to activated
        if (mAdapter.getSelectedItemCount() > i) {
            enableActionMode(i);
        } else {


            Toast.makeText(getApplicationContext(), "Read: hola" + message.getParadas() + message.getVehiculo(), Toast.LENGTH_SHORT).show();

            Intent saag_intent = new Intent(ge_MainActivity.this,
                    ge_Traker_maps.class);

            saag_intent.putExtra("ruta", Item_List.get(i));
            saag_intent.putExtra("vehiculo", Item_List.get(i));
            startActivity(saag_intent);

        }
    }

如何将Extra 放入我的recyclerView 中,并使用我使用的示例代码

【问题讨论】:

  • 您确定您使用的是 recyclerview 吗?还是 listview

标签: java android


【解决方案1】:

试试这个

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                // do on item click
            }
        });

它将解决以下问题

无法解析符号“ListitemClickListener”

【讨论】:

    猜你喜欢
    • 2018-01-15
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 2020-10-20
    • 2018-09-21
    • 1970-01-01
    • 2020-08-21
    • 2017-10-20
    相关资源
    最近更新 更多