This is the code I could write so far. Can some body help me?
- Code: Select all
[syntax="java"]
package com.mallik.andriod.hello;
import android.app.ListActivity;
import java.util.Hashtable;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class HelloAndriod extends ListActivity {
private ListAdapter mAdapter;
String[][] data = new String[100][2];
Hashtable h1 = new Hashtable(500,(float)0.75);
Hashtable h2 = new Hashtable(500,(float)0.75);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] s = new String [] {People._ID,People.NAME,People.PRIMARY_PHONE_ID,
People.NUMBER};
int[] names1 = new int[] {R.id.row_entry};
//int[] names2 = new int[] {R.id.row_entry};
String[] columns = new String[] {People.NAME,People.NUMBER};
Cursor c = getContentResolver().query(People.CONTENT_URI,s,null,null,null);
/*
* startManagingCursor(c);
* Cursor cur = managedQuery(People.CONTENT_URI, s, null, null, null );
*
*/
if (c.moveToFirst()) {
String name = null;
int phoneid = 0;
String phoneno = null;
do {
name = c.getString(c.getColumnIndex(People.NAME));
phoneid = c.getInt(c.getColumnIndex(People.PRIMARY_PHONE_ID));
phoneno = c.getString(c.getColumnIndex(People.NUMBER));
h1.put(name,(int)phoneid);
h2.put(phoneid, phoneno);
} while (c.moveToNext());
}
mAdapter = new SimpleCursorAdapter(this,R.layout.main,c,columns,names1);
setListAdapter(mAdapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Intent I = new Intent(Intent.ACTION_CALL);
long phoneId= 0;
Integer In = (Integer)h1.get("Rel");
String s1 = (String)h2.get(position+1);
int rpos=In.intValue();
if (s1.startsWith("+91")) phoneId= (int)rpos;
else phoneId= (int)(position+1);
I.setData(ContentUris.withAppendedId(Phones.CONTENT_URI, phoneId));
startActivity(I);
}
}[/syntax]


