BottomNavigationのアイコンをタップした際に
ListView(商品一覧)を表示したいのですが、うまくいきません。
どのようにすれば、アイコンタッチでListViewを表示できますでしょうか?
java
1【Product.java】 2 3public class Product extends Fragment { 4 5 @Override 6 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 7 View rootView = inflater.inflate(R.layout.product, container, false); 8 return rootView; 9 } 10} 11
java
1【ProductListItem.java】 2 3public class ProductListItem { 4 private Bitmap mThumbnail = null; 5 private String mTitle = null; 6 7 /** 8 * 空のコンストラクタ 9 */ 10 public ProductListItem() {}; 11 12 /** 13 * コンストラクタ 14 * @param thumbnail サムネイル画像 15 * @param title タイトル 16 */ 17 public ProductListItem(Bitmap thumbnail, String title) { 18 mThumbnail = thumbnail; 19 mTitle = title; 20 } 21 22 /** 23 * サムネイル画像を設定 24 * @param thumbnail サムネイル画像 25 */ 26 public void setThumbnail(Bitmap thumbnail) { 27 mThumbnail = thumbnail; 28 } 29 30 /** 31 * タイトルを設定 32 * @param title タイトル 33 */ 34 public void setmTitle(String title) { 35 mTitle = title; 36 } 37 38 /** 39 * サムネイル画像を取得 40 * @return サムネイル画像 41 */ 42 public Bitmap getThumbnail() { 43 return mThumbnail; 44 } 45 46 /** 47 * タイトルを取得 48 * @return タイトル 49 */ 50 public String getTitle() { 51 return mTitle; 52 } 53}
java
1【ProductListAdapter】 2public class ProductListAdapter extends ArrayAdapter<ProductListItem> { 3 4 private int mResource; 5 private List<ProductListItem> mItems; 6 private LayoutInflater mInflater; 7 8 /** 9 * コンストラクタ 10 * @param context コンテキスト 11 * @param resource リソースID 12 * @param items リストビューの要素 13 */ 14 public ProductListAdapter(Context context, int resource, List<ProductListItem> items) { 15 super(context, resource, items); 16 17 mResource = resource; 18 mItems = items; 19 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 20 } 21 22 @Override 23 public View getView(int position, View convertView, ViewGroup parent) { 24 View view; 25 26 if (convertView != null) { 27 view = convertView; 28 } 29 else { 30 view = mInflater.inflate(mResource, null); 31 } 32 33 // リストビューに表示する要素を取得 34 ProductListItem item = mItems.get(position); 35 36 // サムネイル画像を設定 37 ImageView thumbnail = (ImageView)view.findViewById(R.id.product_thumbnail); 38 thumbnail.setImageBitmap(item.getThumbnail()); 39 40 // タイトルを設定 41 TextView title = (TextView)view.findViewById(R.id.title); 42 title.setText(item.getTitle()); 43 44 return view; 45 } 46}
あなたの回答
tips
プレビュー