ListViewを持つフラグメントがrow
個あります。 row
はで構成されてちょうど私がこのListView
を埋めるためにResourceCursorAdapter
を持ってImageView
Android。リストビューのアイテムをonClickすると、新しい子フラグメントに内部ボタンが表示されます。
fragment_1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment1">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"/>
</RelativeLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip">
<!-- Rightend Play Button. -->
<ImageView
android:id="@+id/play_button"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/ic_play"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
ています。私は各ImageViewにクリックリスナーを割り当てます。提供されたパスに保存されたレコードを再生します。
private abstract class MyAdapter extends ResourceCursorAadpter {
@Override
public void bindView(View view, Context context, final Cursor cursor) {
// Play button.
ImageView playButton = (ImageView) view.findViewById(R.id.play_button);
playButton.setOnClickListener(new View.OnClickListener() {
String record = cursor.getString(cursor.getColumnIndex(DbAdapter.RECORD));
public void onClick(View v) {
// Play record in path [record]. Not the problem.
}
});
}
}
は、今私はrow
クリックで新しいフラグメントFragment_2
を開きたいです。このフラグメントは同じplay_buttonを持ち、同じレコードを再生する必要があります。
fragment_2.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_audio"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment2">
<!-- Play Button. -->
<ImageView
android:id="@+id/play_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_play"/>
</RelativeLayout>
は、どのように私は、このボタンはFragment_1
に比べて同じレコードを果たしていることを管理することができますか?私はレコードのパスで隠れたTextViewを持つことができますが、よりスマートなソリューションを持っているかどうかは確かです。
私のonCreateView
はFragment_1
です。
mList = (ListView) root.findViewById(R.id.list);
// Click event for single row.
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO: Go to fragment_2 and has the same view [view.findViewById(R.id.play_button)]
}
});
あなたの問題を編集して問題を明確に述べることをお勧めします。また、画像の代わりにポストコードを書いてください。 –
@ AjayP.Prajapati申し訳ありませんが、コードをアップロードする際に問題がありましたが、今はすべて正しいです。問題について不明な点はありますか? –