現在、連絡先のリストを表示する必要があるアプリケーションに取り組んでいます。名前をクリックすると、この連絡先に関する情報が表示された新しい画面が表示され、電話番号を選択して電話をかけることができます。でも、
リスト内の名前の横に通話アイコン (現在は ImageView) を追加したいのですが、ユーザーが名前の代わりに通話アイコンを押すと、情報ページに移動する代わりに、電話がすぐにそのユーザーに電話をかけます。
すでに画像を行に追加してクリック可能にしましたが、onClickListener を実装する方法がまったくわかりません。私は多くの検索を行ってきましたが、ほとんどのチュートリアルは行に画像を追加する方法のみを説明しているようですが、OnClickListener を追加して何かをさせる方法は説明していません。
リストと行のそれぞれの 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>
行の場合は次のとおりです。
<?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 メモ帳のチュートリアルのコードの一部を認識している方もいるでしょう。これは、メモ帳のコードを使用してカスタムの連絡先リストを作成したためです。私は優れたプログラマーではないので、何かを始める必要がありました。
画面イメージはこちら
私が持っているのは、ユーザーが名前の 1 つを選択すると、このユーザーの情報ページに移動することです。私が欲しいのは、ユーザーが連絡先の右側にある電話を選択すると、電話が自動的にこのユーザーの電話番号に電話をかけることです。これどうやってするの?