Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

java - How putExtra in RecyclerView with arraylist from JSON

I'm try to go another activity, from RecyclerView with determined position, and i need putExtra for load info in the destin activity.

I'm based in this example, but i have problem when I call JSON file.

The Sample code is this:

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) {…

I have problema in this line, I not know like fix

listview.setOnItemClickListener(new ListitemClickListener());

Show me this error: Cannot resol symbol 'ListitemClickListener'

since my click method is different

   @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);

        }
    }

how could putExtra in my recyclerView, with this code for sample that i use

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this

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

it will fix below issue

Cannot resol symbol 'ListitemClickListener'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...