我制作了一个列表视图,其中有2个对象,名称&电话。现在,我想点击列表视图,并使用列出的电话号码拨打电话
我不知道该怎么做。请帮忙。感谢。
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Express extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activitylink.getInstance().addActivity(this);
final String Item_Name = "NAME", Item_Hotline = "HOTLINE";
ArrayList<HashMap<String,String>> myListData = new ArrayList<HashMap<String,String>>();
String[] hotlines = new String[]{ "11112222" , "22223333", "44445555" };
for( int i=0;i<getResources().getStringArray(R.array.item).length ; ++i) {
HashMap<String,String> item = new HashMap<String,String>();
item.put(Item_Name,getResources().getStringArray(R.array.item)[i]);
item.put(Item_Hotline,hotlines[i]);
myListData.add(item);
}
setListAdapter( new SimpleAdapter(
this,
myListData,
R.layout.list_item,
new String[] { Item_Name, Item_Hotline },
new int[] { android.R.id.text1, android.R.id.text2 } )
);
}
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
}
}
}
答案 0 :(得分:0)
试试这个,希望这会对你有帮助......
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
String hotline = (String) myListData.get((int) id)
.values().toArray()[1];
Log.d("hotline", hotline);
callHotline(hotline);
}
}
private void callHotline(String hotlineStr){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+hotlineStr));
startActivity(callIntent);
}
答案 1 :(得分:0)
@覆盖 public void onListItemClick(ListView列表,View v,int position,long id) { String hotline = myListData.get(position);
Intent tocall = new Intent(Intent.ACTION_CALL);
tocall.setData(Uri.parse("tel:"+hotline ));
startActivity(tocall);
}
}
答案 2 :(得分:0)
OnItemClickListener
:
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + hotlines[position]));
startActivity(callIntent);
}
}