Clans / FloatingActionButton

Android Floating Action Button based on Material Design specification
Apache License 2.0
5.22k stars 1.13k forks source link

Label is getting passed in OnClick() when i click fab buttons label instead of FAB button instance #311

Open akshay-shah opened 8 years ago

akshay-shah commented 8 years ago

i add fab buttons like this

floatingMenuSort.setVisibility(View.VISIBLE); for (int i = 0; i < sort_options_title.size(); i++) { FloatingActionButton fab = new FloatingActionButton(CategoryListActivity.this); fab.setButtonSize(FloatingActionButton.SIZE_MINI); fab.setLabelText(sort_options_title.get(i)); fab.setColorNormal(Color.parseColor("#00aeef")); fab.setColorPressed(Color.parseColor("#00aeef")); fab.setColorRipple(Color.parseColor("#00aeef")); fab.setTag(sort_option_value.get(i)); fab.setOnClickListener(CategoryListActivity.this); switch (sort_option_value.get(i)) { case "pops": fab.setImageResource(R.drawable.popular); break; case "priceltoh": fab.setImageResource(R.drawable.sortasce); break; case "pricehtol": fab.setImageResource(R.drawable.sortdesc); break; case "discount": fab.setImageResource(R.drawable.percent); break; } floatingMenuSort.addMenuButton(fab); }

so in onclick i recieve an instance of label when label is clicked whereas i should recieve instance of fab button

givolaj commented 7 years ago

i did this to solve that problem (which is annoying!): after adding the fabButton with addMenuButton, i've set the tags, on both button and label, like so: listFab.addMenuButton(b); b.setTag(o.getString("id")); View label = (View) b.getTag(R.id.fab_label); if(label != null) label.setTag(o.getString("id")); hope that helps, cheers

kris-sum commented 5 years ago

You can also work around this problem by calling addMenuButton(fab) BEFORE calling setOnClickListener