2011-01-22 11 views
2

私は友人のリストを表示するアプリを持っています(それぞれの友人はfullNameとmovilephoneを持っています)。私は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); 
      } 
     }); 
    } 

} 

答えて

1

あなたは、このゾルを使用することができますクリックボタンから呼び出すには: How to make a phone call in android and come back to my activity when the call is done?


とバックウル活性に取得するには問題解決のためには、このゾルを試してみてください取り戻すのhttp://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html

+0

ウィッヒの問題?私はその問題を知らなかった – NullPointerException

+0

また、list_itemにボタンを追加するのはどうですか? – NullPointerException

+0

コールアクティビティを追加すると、それは電話アクティビティに移動するよりも、thrからurアプリケーションに戻ってくるよりも、2番目のlnikで定義されたリスナを追加し、コールが完了したらurアクティビティを呼び戻す必要があります。 –

関連する問題