to retrive contact list to a particular view

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

to retrive contact list to a particular view

Postby debasish » Mon Aug 23, 2010 12:46 pm

hi i am new to Android & java trying to retrieve contact name in a particular list view i wrote fallowing code but only able to get first contact name in all the frame of the view ,i might have problem in while loop pls help

my code
public class listview extends Activity
{

//private static int position = 0;

// Context declaration
Context context; // Current context of the activity

private LayoutInflater mInflater;


ListView mListView; // List to display file information
SimpleAdapter mListAdapter; // Adapter to set the list

// Strings declaration
private String ICON = "icon"; // For the icon on every row
private String CONTACTNAME = "Name"; // For file name in every row
private String FACEBOOK = "facebook"; // For file duration in every row
//private String DATETIME = "Date"; // For the creation date/time in every row
//private String BUTTON = "Button";
// Other objects declaration
View listItem;
String[] names;
public int getCount() {
return names.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}


public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.icon = (ImageView) convertView
.findViewById(R.id.list_item_icon);
holder.text2 = (TextView) convertView
.findViewById(R.id.contact_name);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// holder = (ViewHolder) convertView.getTag();
// holder.icon.setTag(curr[position]);
// holder.text2.setText(names[position]);

return convertView;
}

static class ViewHolder {
ImageView icon;
TextView text2;
}


// OnCreate method is called first of all when execution starts
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO Auto-generated method stub


setContentView(R.layout.main1);


ListView mListView = (ListView) findViewById(R.id.ListView01);



//if (names != null && names.length > 0);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
{

Map<String, Object> map = new HashMap<String, Object>();

Cursor cur = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(cur);

// private void getColumnData(Cursor cur){
if (cur.moveToFirst()) {

String name;
// String phoneNumber;
int nameColumn = cur.getColumnIndex(People.NAME);
// int phoneColumn = cur.getColumnIndex(People.NUMBER);
// String imagePath;
name = cur.getString(nameColumn);
map.put(CONTACTNAME, name);
do {
// Get the field values
name = cur.getString(nameColumn);

// Do something with the values.
// ..
map.put(CONTACTNAME, name);

list.add(map);


} while (cur.moveToNext());



}
}

//ListView mListView = (ListView) findViewById(R.id.ListView01);


mListAdapter = new SimpleAdapter(this, list, R.layout.list_item,

new String[] { ICON, CONTACTNAME, FACEBOOK }, new int[] {
R.id.list_item_icon, R.id.contact_name, R.id.facebook });
mListView.setAdapter(mListAdapter);




}


}





Thanks in advance
debasish
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 23, 2010 12:30 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: Google Feedfetcher and 4 guests