【问题标题】:How can I add a button that makes a phone call to a programmatically given phone number?如何添加一个按钮来拨打以编程方式给定的电话号码?
【发布时间】:2018-06-18 11:49:22
【问题描述】:

我有一个应用程序,显示朋友列表(每个朋友都有全名和手机)。

我正在使用 android 开发者指南的 listActiviti 示例的变体

谁能完成我的代码或告诉我如何在每个列表的项目右侧放置一个按钮的代码示例,当用户按下该按钮时,电话会拨打该用户的电话号码。此外,现在,当用户按下列表项(而不是按钮)时,它会打开一个新活动来显示朋友的详细信息......此功能必须与按钮分开工作

这是我的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>

这是我的 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 = MyApplication.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);
          }
        });
    }
}

【问题讨论】:

    标签: android listactivity phone-call


    【解决方案1】:

    【讨论】:

    • 返回的问题有哪些??我不知道这个问题
    • 还有如何在 list_item 中添加一个按钮?
    • 当您添加通话活动时,它将转到电话活动,而不是从 thr 回到您的应用程序,您必须添加在第二个 lnik 中定义的侦听器,并在通话完成时回叫您的活动
    • 我已经给出了代码,你必须自己添加按钮,只需使用第一个链接来添加通话活动
    • 没问题,但现在我不知道如何将按钮放入我的列表视图
    猜你喜欢
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多