我想從片段列表視圖中獲取數據並在底部圖紙佈局中查看它。我想查看上面的附加圖像。請幫幫我。 如何將數據從片段傳遞給android中的底部表單?
我完成了查看底部表單的代碼,當用戶單擊列表視圖項目時,底部表單將被打開。在底部表單中,應該在底部表單中查看片段中的列表視圖項目詳細信息。我的代碼項目如下。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_call_log, container, false);
callLogList = (ListView) v.findViewById(R.id.callLogList);
contactPhoto = (ImageView) v.findViewById(R.id.missedImage);
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getActivity());
View bottomSheetView = inflater.inflate(R.layout.bottom_sheet,null);
bottomSheetDialog.setContentView(bottomSheetView);
String[] textString = new String[]{"Play", "Share", "Call", "add Notes","Add To Block","Delete"};
int[] drawableIds = new int[]{R.drawable.play_icon, R.drawable.share_icon, R.drawable.call_icon, R.drawable.add_notes_icon,
R.drawable.block_icon,R.drawable.delete_icon};
final ListView listbottom = (ListView)bottomSheetDialog.findViewById(R.id.listBottomSheets);
CustomAdapter adapter = new CustomAdapter(this, textString, drawableIds);
listbottom.setAdapter(adapter);
listbottom.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
switch (position)
{
case 0:
Toast.makeText(getActivity(),"playing the song",Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getActivity(),"sharing the song",Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getActivity(),"deleting the song",Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(getActivity(),"blocking the song",Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(getActivity(),"nothing selected ",Toast.LENGTH_SHORT).show();
break;
}
}
});
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) bottomSheetView.getParent());
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
bottomSheetBehavior.setPeekHeight(320);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
Toast.makeText(getActivity(),"Hidden",Toast.LENGTH_SHORT).show();
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
callLogList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
bottomSheetDialog.show();
}
});
setRetainInstance(true);
return v;
}
「myDataArrayListToDisplayInBottomSheet」這意味着放置在片段中的列表視圖的數組列表數據 –
事實上,如果這是您想要在bottomSheet中顯示的數據。 –