So far I have this code from examples I have seen on here:
public class testLayout extends Activity {
final int PICK_CONTACT = 0;
ImageView image = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image=(ImageView)findViewById(R.id.icon);
image.setOnClickListener(onChangePerson);
}
private View.OnClickListener onChangePerson=new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
}
};
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst())
{
String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
}
}
break;
}
}
}
This allows me to open up an activity that correctly shows the contacts on the phone, and let's me choose a contact. However, everytime I click on a contact, the program crashes. Any ideas why this is happening? Thanks