last day (14 days later) » 

07:42
8
A: Displaying Contact Number and Contact Name in a custom list view

RaghunandanSince op asked for the solution using custom adapter i have posted the below.(from the comments) Display.java public class Display extends Activity implements OnItemClickListener{ List<String> name1 = new ArrayList<String>(); List<String> phno1 = new ArrayList<String>(); MyAdapter ...

sure give me a moment.
@user2511882 i updated my post let me know if you need further assistance
change it to Display.this. a copy paste error. that's Activity context. Your ActivityName.this is the Acctivity context.
@Darkie ask a different question. Why do you ask a question in comment section.
This code shows some of my contacts with repetitive values :(
@kgandroid no it does not. Secondly you should be using a CursorAdapter. This method is not efficient
Cant understand what mistake I ma doing :( :(
The name and numbers are printed in my log but not in the sorted order.But when I bind them in list all goes wrong.It shows only 3-4 repetative contacts
@kgandroid how can i without seeing the code.
07:42
pastebin.com/TMyjiur8 here it is.Please have a look
@kgandroid your adapter code is where the problem is. Fix it.
Can you please tell me the mistake i am doing??
Hello
Your getView is not right
You shoudl read about listview recycling mechanism
yes there was a mistake in getview and i solved it.Thanks for your time.
But the contacts are not coming in sorted alphabetical order
any thought on that??
You can use a Comparotor for your adapter
getview must be
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null)
{

convertView= mInflater.inflate(R.layout.addtocirclelistrow,null);
holder = new ViewHolder();
holder.tvname=(TextView)convertView.findViewById(R.id.rowTextView);
holder.cb=(CheckBox)convertView.findViewById(R.id.cbselect);
holder.tvnum=(TextView)convertView.findViewById(R.id.tvnum);
holder.setTag(convertView);

}
else
{
holder = (ViewHolder)convertView.getTag();
}

holder.tvname.setText(name1.get(position));
To sort
adapter.sort(comparator);
08:05
to sort i found this:
Comparator<String> ALPHABETICAL_ORDER1 = new Comparator<String>() {
public int compare(String object1, String object2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(object1.toString(), object2.toString());
return res;
}
};

Collections.sort(your array name, ALPHABETICAL_ORDER1);
But how can i use it?
08:31
I have done this:
Comparator<String> ALPHABETICAL_ORDER1 = new Comparator<String>() {
public int compare(String object1, String object2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(object1.toString(), object2.toString());
return res;
}
};
and then: Collections.sort(name1, ALPHABETICAL_ORDER1);
But this causing the name to be sorted perfectly but not the numbers

last day (14 days later) »