Reputation: 307
i have listview the fisrt time i when i click to row it open the context menu then i override the oncontextitemselected
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case CALL_ID:
{
AdapterContextMenuInfo info2 = (AdapterContextMenuInfo) item.getMenuInfo();
String phone=mDbHelper.getPhone(info2.id);
String toDial="tel:"+phone.toString();
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse(toDial)));
return true;
}
}
return super.onContextItemSelected(item);
}
this do correctly but when i
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case CALL_ID:
{
AdapterContextMenuInfo info2 = (AdapterContextMenuInfo) item.getMenuInfo();
String phone=mDbHelper.getPhone(info2.id);
String toDial="tel:"+phone.toString();
startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse(toDial)));
return true;
}
return super.onMenuItemSelected(featureId, item);
}
}
the app crashed can u show me the difference between them
Upvotes: 0
Views: 1229
Reputation: 715
Try this:
context_menu.xml (res/menu/context_menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/call"
android:title="CALL" />
</menu>
Context Menu:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
info = (AdapterView.AdapterContextMenuInfo)menuInfo;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
String phone="555-555-555";
String toDial="tel:"+phone.toString();
Uri uri = Uri.parse(toDial);
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
return true;
default:
return super.onContextItemSelected(item);
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
That should work.
Upvotes: 2