Как передавать даные из ListView в TextView, который находится в DialogFragment?
Но в ListView передается три массива данных и каждый из них нужно передать в один из TextView.
public class DialogFragment extends android.support.v4.app.DialogFragment{
TextView tvF_Name, tvL_Name, tvB_Day;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
tvF_Name = (TextView) getActivity().findViewById(R.id.tvF_Name);
tvL_Name = (TextView) getActivity().findViewById(R.id.tvL_Name);
tvB_Day = (TextView) getActivity().findViewById(R.id.tvB_Day);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_fragment, null);
builder.setView(view).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setCancelable(false);
return builder.create();
}
}
final ListAdapter listAdapter = new SimpleAdapter(activity.getApplicationContext(),
arrayList,
R.layout.simple_list_item,
from,
to);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DialogFragment dialogFragment = new DialogFragment();
Bundle bundle = new Bundle();
String f_name = listAdapter.getItem(position).toString();
bundle.putString("name", f_name);
dialogFragment.setArguments(bundle);
dialogFragment.show(activity.getSupportFragmentManager(), "Dialog");
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tvF_Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp" />
<TextView
android:id="@+id/tvL_Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp" />
<TextView
android:id="@+id/tvB_Day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="18sp" />
</LinearLayout>