Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you very much for all the given support. I used the approach which @Richard provided with @rafael-t's Tag concept. Thanks @yashwanth-kumar for the explanation. Following are the modifications did to my original codes </p> <pre><code>public ArrayList&lt;Object&gt; getNames(String response){ ArrayList&lt;Object&gt; arrList = null; try { JSONObject json = new JSONObject(response); String values = json.getString("friends"); JSONArray jsonArray = new JSONArray(values); arrList = new ArrayList&lt;Object&gt;(); for (int i = 0; i &lt; jsonArray.length(); i++) { arrList.add(new User(jsonArray.getJSONObject(i).getString("id"),jsonArray.getJSONObject(i).getString("fname"),jsonArray.getJSONObject(i).getString("lname"),jsonArray.getJSONObject(i).getString("email"))); } } catch (Exception e) { e.printStackTrace(); } return arrList; } </code></pre> <p>This is my getNames Method I added all the values to User Object. Thanks to @Richard .</p> <p>Here is my Custom Adapter for this change </p> <pre><code>package virtualpathum.web; import java.util.ArrayList; import java.util.Iterator; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; public class MyArrayAdapter extends ArrayAdapter&lt;ArrayList&lt;Object&gt;&gt; { private final Activity context; private final ArrayList names; @SuppressWarnings("unchecked") public MyArrayAdapter(Activity context, ArrayList names) { super(context, R.layout.friend, names); this.context = context; this.names = names; } // static to save the reference to the outer class and to avoid access to // any members of the containing class static class ViewHolder { public ImageView imageView; public TextView textView; public ImageButton ibConfirm; public ImageButton ibNotNow; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder will buffer the assess to the individual fields of the row // layout ViewHolder holder; // Recycle existing view if passed as parameter // This will save memory and time on Android // This only works if the base layout for all classes are the same View rowView = convertView; if (rowView == null) { LayoutInflater inflater = context.getLayoutInflater(); rowView = inflater.inflate(R.layout.friend, null, true); holder = new ViewHolder(); holder.textView = (TextView) rowView.findViewById(R.id.txtName); holder.imageView = (ImageView) rowView.findViewById(R.id.icon); //holder.ibConfirm = (ImageButton) rowView.findViewById(R.id.ibNotNow); //holder.ibNotNow= (ImageButton) rowView.findViewById(R.id.ibNotNow); rowView.setTag(holder); } else { holder = (ViewHolder) rowView.getTag(); } String [] frndNames = new String[names.size()]; int count = 0; for (@SuppressWarnings("rawtypes") Iterator iterator = names.iterator(); iterator.hasNext();) { User user = (User) iterator.next(); frndNames[count] = user.getFirstname()+" "+user.getLastname(); count++; } String [] frndIds = new String[names.size()]; int idCount = 0; for (@SuppressWarnings("rawtypes") Iterator iterator = names.iterator(); iterator.hasNext();) { User user = (User) iterator.next(); frndIds[idCount] = user.getUserid(); idCount++; } holder.textView.setText(frndNames[position]); holder.textView.setTag(frndIds[position]); holder.imageView.setImageResource(R.drawable.man); return rowView; } } </code></pre> <p>This is the on click Listener </p> <pre><code>@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // Get the item that was clicked String userid = (String) v.findViewById(R.id.txtName).getTag(); Toast.makeText(this, "Selected user ID = "+userid , Toast.LENGTH_LONG) .show(); } </code></pre> <p>I still feel this can be further optimize for better performance but for now it's more than enough for me. Thank you guys again. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload