我有一个应用程序,显示了一个朋友列表(每个朋友都有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);
}
});
}
}
答案 0 :(得分:1)