현재 리스트뷰를 사용하고 add를 통해 리스트뷰에 값들을 넣었습니다.
매겨변수로 넘겨준 값들은 Drawable과 String인데요
리스트뷰를 클릭시 A fragment에서 B fragment로 사진값과 String값들을 넘겨주려고 합니다.
String이야 bundle.putString으로 넘겨주면 되는데 Drawable같은 경우에는 넘겨줄 수 있는 방법이 없네요...
혹시 bundle을 통해 fragment간에 drawable이나 imageview정보를 넘겨줄 수 있는 방법이 있을까요...?
참고용으로 밑에 코드를 올립니다! 안드로이드 고수님들 부탁드립니다 ㅠ
A fragment
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
MenuListViewItem item = (MenuListViewItem) parent.getItemAtPosition(position);
Drawable menuImage = item.getMenuImage();
String menuName = item.getMenuName();
String menuPrice = item.getMenuPrice();
OrderFragment orderFragment = new OrderFragment();
Bundle bundle = new Bundle();
bundle.putString("menuImage", String.valueOf(menuImage));
bundle.putString("menuName", menuName);
bundle.putString("menuPrice", menuPrice);
orderFragment.setArguments(bundle);
FragmentManager manager1 = getFragmentManager();
manager1.beginTransaction().replace(R.id.content, orderFragment).commit();
}
});
B Fragment
ImageView orderImage = v.findViewById(R.id.orderImage);
TextView orderName = v.findViewById(R.id.orderName);
TextView orderPrice = v.findViewById(R.id.orderPrice);
String menuImage = getArguments().getString("menuImage");
String menuName = getArguments().getString("menuName");
String menuPrice = getArguments().getString("menuPrice");
orderImage.setImageResource(Integer.parseInt(menuImage));
orderName.setText(menuName);
orderPrice.setText(menuPrice);