android – 酥脆片段按钮不工作

android – 酥脆片段按钮不工作,第1张

概述我有一个片段,我正在使用面包刀. public class FooFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = i 我有一个片段,我正在使用面包刀.
public class FooFragment extends Fragment {    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) {        VIEw vIEw = inflater.inflate(R.layout.foo,container,false);        ButterKnife.inject(this,vIEw);        return vIEw;    }    @OnClick(R.ID.some_btn)    public voID somebuttonOnClick() {        // do something    }}

但是,当按钮在屏幕上轻击时,一直不会调用somebuttonOnClick方法.

想想我在做什么错误的面包框架?

这是正在使用的布局:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    androID:background="@color/White">    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal">        <button            androID:ID="@+ID/some_btn"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:layout_margin="@dimen/xsmall_margin"            androID:background="@drawable/some_btn_selection" />        <button            androID:ID="@+ID/some_other_btn"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:layout_margin="@dimen/xsmall_margin"            androID:background="@drawable/some_other_btn_selection" />    </linearLayout></linearLayout>
解决方法 最新的ButterKnife 8.0.1 6月-2016

InjectVIEw和注入已被BindVIEw替换并绑定
这是以下步骤: –

投票
取消接受
从Butterknife github页面:

将其添加到项目级build.gradle中:

buildscript {  repositorIEs {    mavenCentral()   }  dependencIEs {    classpath 'com.neenbedankt.gradle.plugins:androID-apt:1.8'  }}

将其添加到您的模块级build.gradle中:

apply plugin: 'androID-apt'androID {  ...}dependencIEs {  compile 'com.jakewharton:butterknife:8.0.1'  apt 'com.jakewharton:butterknife-compiler:8.0.1'}

然后用这样的面包刀

private Unbinder unbinder;    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,Bundle savedInstanceState) {        // Inflate the layout for this fragment        VIEw calcVIEw = inflater.inflate(R.layout.content_main,false);        unbinder = ButterKnife.bind(this,calcVIEw);        return calcVIEw;    }    @OverrIDe    public voID onDestroyVIEw() {        super.onDestroyVIEw();        unbinder.unbind();    }    @OnClick(R.ID.one)    public voID one() {        Toast.makeText(getActivity(),"Working",Toast.LENGTH_SHORT).show();        result.setText(result.getText().toString() + 1);    }
总结

以上是内存溢出为你收集整理的android – 酥脆片段按钮不工作全部内容,希望文章能够帮你解决android – 酥脆片段按钮不工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1132305.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存