我目前正在开发一个需要显示联系人列表的应用程序。您可以单击他们的姓名,它会将您带到一个新屏幕,显示有关此联系人的信息,并允许您通过选择他们的电话号码来呼叫他们。然而,
我想在列表中的名称旁边添加一个呼叫图标(当前为 ImageView),当用户按下呼叫图标而不是名称时,电话会立即呼叫该用户而不是转到信息页面。
我已经将图像添加到该行并使其可点击,但我完全不知道如何为其实现 onClickListener。我做了很多搜索,但大多数教程似乎只解释了如何将图像添加到一行,而不是如何向它添加 OnClickListener 并让它做一些事情。
下面分别是 List 和 Row 的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/no_notes"/>
</LinearLayout>
这是 Row 的一个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="260dp"
android:layout_height="60dp"
android:focusable="false"
android:textColor="#FFF"
android:textSize="26sp" />
<ImageView
android:id="@+id/phoneButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/text1"
android:layout_toRightOf="@id/text1"
android:clickable="true"
android:contentDescription="TODO"
android:focusable="false"
android:src="@android:drawable/sym_action_call" />
</RelativeLayout>
这是 onListItemClick 方法:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, PersonalPhonebookView.class);
i.putExtra(NotesDbAdapter.KEY_ROWID, id);
startActivityForResult(i, ACTIVITY_VIEW);
}
你们中的一些人可能会认出 Android 记事本教程中的代码片段。那是因为我使用记事本代码创建了一个自定义联系人列表。我不是一个好的程序员,所以我需要一些东西来开始。
这是屏幕的图像
我所拥有的是当用户选择其中一个名称时,他会转到该用户的信息页面。我想要的是当用户选择联系人右侧的电话时,电话会自动呼叫该用户的电话号码。我怎样才能做到这一点?