SETTING EXTRA VARIABLES TO A BUTTONCLICKLISTENER IN LISTVIEW

Pooja Malohtra

Total Post:47

Points:331
Posted by  Pooja Malohtra
 1454  View(s)
Ratings:
Rate this:

in my app i have a listview(asynctask) getting all the users from external database. Each row of my listview contains an image that the user can interact. When user presses that image i try to start a new intent by using the data that i already have(by using putExtra while starting the intent.) Listview works fine - it gathers all the data from database. But, the putExtra values are same for each row. I will appreciate if you can help me regarding that matter.

Code is as follows; The important part is below

ImageView showlastonmap = (ImageView)v.findViewById(R.id.showlastonmap);
where i try to add putExtra.
 @Override
    protected void onPostExecute(JSONObject json) {
        pDialog.dismiss();
        try {
 
            if (json.getString(KEY_SUCCESS) != null) {
                String res = json.getString(KEY_SUCCESS);
 
                //Invitation count
 
                Integer inv =  json.getInt("invitation");
                setNotifCount(inv);
 
                if(Integer.parseInt(res) == 1) {
 
                    // Getting JSON Array from URL
 
                    android1 = json.getJSONArray(TAG_LOCATIONDATA);
                    for (int i = 0; i < android1.length(); i++) {
                        JSONObject c = android1.getJSONObject(i);
 
                        // Storing  JSON item in a Variable
                        final String ver = c.getString("username");
                        final String dataenlem = c.getString("enlem");
                        final String databoylam = c.getString("boylam");
                        final String datazaman = c.getString("zaman");
 
                        /*----------to get City-Name from coordinates ------------- */
                        StringBuffer address = new StringBuffer();
                        Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
                        List<Address> addresses;
                        try {
                            addresses = gcd.getFromLocation(Double.parseDouble(dataenlem), Double.parseDouble(databoylam), 1);
 
                            if (addresses.size() > 0)
                               // System.out.println(addresses.get(0).getLocality());

 

  1. Andrew Watson

    Post:39

    Points:273
    Re: Setting extra variables to a buttonclicklistener in listview

    you should do :

     Intent login = new Intent(getApplicationContext(),
               HaritaLastSolo.class);
             login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
               login.putExtra("enlem", oslist.get(position).get("enlem"));
               login.putExtra("boylam", oslist.get(position).get("boylam"));
              startActivity(login);

      Modified On Apr-08-2018 11:56:41 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!