我有以下Butterknife的onclick不片段觸發方法
public class InventoryFragment extends Fragment {
@BindView(R.id.fab_fragment_inventory)FloatingActionButton mFab;
private Unbinder unbinder;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//return super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_inventory, container, false);
unbinder = ButterKnife.bind(this, view);
return view
}
@OnClick(R.id.fab_fragment_inventory)
public void newItemDialog(){
// do stuff
}
當我把方法上的XML,它拋出這個錯誤
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_fragment_inventory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:elevation="4dp"
android:onClick="newItemDialog"
android:src="@drawable/vector_plus"
app:layout_anchorGravity="bottom|right|end"/>
> java.lang.IllegalStateException: Could not find a method
> newItemDialog(View) in the activity class
> simpleinventory.simpleinventory.activities.InventoryActivity for
> onClick handler on view class
> android.support.design.widget.FloatingActionButton with id
> 'fab_fragment_inventory'
這裏是我的gradle這個
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.jakewharton:butterknife:8.1.0'
}
編輯 未能通過ñ,我沒有在第一次onclick。沒有它沒有發生。
'安卓的onClick = 「newItemDialog」'意味着你申報了''空隙newItemDialog(查看)你的*活動*。去掉它。 – njzk2