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);
}
});
}
}
回來的至極的問題?我不知道這個問題 – NullPointerException 2011-01-22 10:22:51