How can I add a button that makes a phone call to a programmatically given phone number?
I have an app, that shows a list of friends (each friend haves fullName and movilephone).
I'm using a variation of the listActiviti example of android developers guide
can someone complete my code or tell me code examples of how to put a button on the right side of the items of each list, that when the user press on that button, the phone calls to the phone number of that user. Also, now, when the user press on the list item (but not on the button) it's opened a new activity for showing details of the friend... this functionality haves to be working separatedly of the button
this is my list_item.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
and this is my code for the listActivity:
public class AllActivity extends ListActivity {
RemoteConnection con; //conexion remota
private List<Friend> friends; //lista de amigos
private List<String> usernames; //lista de usernames de amigos, para rellenar el listview
static SharedPreferences settings;
static SharedPreferences.Editor configEditor;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings=PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
configEditor = settings.edit();
friends = new ArrayList<Friend>();
usernames = new ArrayList<String>();
con = new RemoteConnection();
actualizar();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 1) {
setResult(1);
finish();
}
}
public void onResume() {
super.onResume();
}
public void actualizar()
{
friends = MyAppl开发者_StackOverflow社区ication.getDatabaseAdapter().retrieveAllFriends();
usernames.clear();
for (int i=0;i<friends.size();i++)
{
usernames.add(i,friends.get(i).getFullName());
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, usernames));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Bundle bundle = new Bundle(); //bundle is like the letter
bundle.putString ("user", friends.get(position).getFullName()); //arg1 is the keyword of the txt, arg2 is the txt
bundle.putString ("email", friends.get(position).getEmail());
bundle.putString ("permission", friends.get(position).getPermission());
Intent i=null;
if (friends.get(position).getPermission().equals("total"))
i = new Intent (AllActivity.this, Locate.class);
else if (friends.get(position).getPermission().equals("perhours"))
i = new Intent (AllActivity.this, LocatePerHours.class);
else
i = new Intent (AllActivity.this, LocatePerDays.class);
i.putExtras(bundle);
startActivity(i);
}
});
}
}
To call from button click you can use this sol: How to make a phone call in android and come back to my activity when the call is done?
and for problem solving to get back on ur activity try this sol:http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
精彩评论