2013-03-07 35 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

相关问题