简体   繁体   中英

How to display details of listview selected item on another activity?

Here is my code... which i displayed listview data... Now i want to fetch other details under this id

I want to fetch from database based on the Growers ID. Which is get from the listview

 public class FarmerDetails extends Activity implements OnClickListener
    {
    private TextView tv;
    private Button btnView;
    private TextView textViewResult;

     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.farmerdetails);

            btnView = (Button) findViewById(R.id.bView);
            textViewResult = (TextView) findViewById(R.id.textViewResult);

            btnView.setOnClickListener(this);
            tv=(TextView) findViewById(R.id.tv1);


     }
     private void getData(final String value) {
         Intent i = getIntent();
            String code = i.getStringExtra("itemValue");
            tv.setText("Grower's ID: "+code);

            String url = Config.DATA_Details+tv.getText().toString().trim();

            StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    showJSON(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(FarmerDetails.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
                }
            });
            }

            RequestQueue requestQueue = Volley.newRequestQueue(this);
            requestQueue.add(stringRequest);
        }

        private void showJSON(String response){
            String ccri="";
            String name="";
            String address="";
            String taluk="";
            String punch = "";
            try {
                JSONObject jsonObject = new JSONObject(response);
                JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
                JSONObject farmerData = result.getJSONObject(0);
                ccri=farmerData.getString(Config.KEY_CCRI);
                name = farmerData.getString(Config.KEY_NAME);
                address = farmerData.getString(Config.KEY_ADDRESS);
                taluk = farmerData.getString(Config.KEY_TALUK);
                punch=farmerData.getString(Config.KEY_PUNCH);
            } 
            catch (JSONException e) 
            {
                e.printStackTrace();
            }
            textViewResult.setText("CCRI Code:\t"+ccri+"Name:\t"+name+"\nAddress:\t" +address+ "\nTaluk:\t"+taluk+"\nPunchayat:\t"+punch);
        }

        @Override
        public void onClick(View v) {
            getData();
        }    
    }

In my code only ID is displaying... fetching is not performing.. Plz help!!

this is kinda complicated.

  1. you'll have to check out if ur url is right. Print the url in console and type it in some browser do the GET request. If there's no response, well it might be your problem. Maybe you did not compose the url right.
  2. if there's some response in step 1, ask the server guy what's going on there. and wait.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM