2013-03-07 37 views
0

因爲我是新來的android我需要幫助從成員的stackoverflow。 在我的android項目中,我有一個公司名稱的字符串數組,其中有相同的字符串數組 - 項中列出的聯繫人號碼。從列表視圖中的號碼使撥打電話

我的列表視圖與列表視圖中的過濾器功能正常工作。 我只希望用戶可以直接從我的列表視圖發起該號碼的電話。

<item >Citizen Company - 731429278838 </item> 

我想用戶可以直接撥打給定的電話號碼。

這裏是我的代碼,請查看並通知我我的錯誤。

public class Taximain extends Activity { 
// List view 
private ListView lv; 
// Listview Adapter 
ArrayAdapter<String> adapter; 
// Search EditText 
EditText inputSearch; 
// ArrayList for Listview 
ArrayList<HashMap<String, String>> productList; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.taxi_main); 
    // Listview Data 
    String products[] = getResources().getStringArray(R.array.Taxi); 
    lv = (ListView) findViewById(R.id.list_view); 
    inputSearch = (EditText) findViewById(R.id.inputSearch); 
    // Adding items to listview 
    adapter = new ArrayAdapter<String>(this, R.layout.taxi_listitem, R.id.product_name, products); 
    lv.setAdapter(adapter); 
    inputSearch.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { 
      // When user changed the Text 
      Taximain.this.adapter.getFilter().filter(cs); 
     } 
     @Override 
     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, 
       int arg3) { 
      // TODO Auto-generated method stub 

     } 
     @Override 
     public void afterTextChanged(Editable arg0) { 
      // TODO Auto-generated method stub 
     } 
    }); 

} 

}

+0

看到我更新的答案。 – Harshid 2013-03-28 13:20:30

回答

1

你們首先你要製作一些公司和他的電話號碼。

與公司和號碼進行自定義列表視圖。

現在您可以使用setOnItemClickListener並撥打電話。

lv.setOnItemClickListener(new OnItemClickListener() 
{ 
     public void onItemClick(AdapterView<?> arg0, View v, int position, long id){ 
      Intent callintent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phone_arr[position])); 
      startActivity(callintent);      
     } 
}); 

您可以使用this listview並進行一些修改。

更新:

Strint [] phone_arr = {1234567890,9999999999,...}

產品總是相同的大小。

+0

先生, 我已修改我的代碼請看看。 – Dexto 2013-03-28 13:07:58

+0

這個工作是不是? – Harshid 2013-03-28 14:09:10

0

您正在尋找特殊IntentACTION_DIAL

我假設你能夠得到的電話號碼很容易,所以這裏的,你會想如何使用它:

String tel = // Get phone number; 

Intent intent = new Intent(Intent.ACTION_DIAL);       
intent.setData(Uri.parse(String.format("tel:%s", tel))); 
startActivity(intent); 
+0

我修改了我的代碼,請看看。 – Dexto 2013-03-28 13:07:31

0

使用意圖「ACTION_CALL」將使從列表視圖項的點擊一個phonecall。

String callString="tel:"+phone_arr[position]; 
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(callString)); 
startActivity(intent); 
+0

@ madhuri- MAM, 請重新看看我的代碼,並建議我請。 – Dexto 2013-03-28 13:08:57

相關問題