Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

android - Unable to use in local variable '@BindViews' not applicable to local variable butterknife

    public class LoginActivity extends AppCompatActivity {

  @BindViews(value = {R.id.logo, R.id.first, R.id.second, R.id.last})
  protected List<ImageView> sharedElements;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    @BindViews({R.id.pager)

    @BindViews(R.id.scrolling_background)
    final AnimatedViewPager pager = ButterKnife.findById(this, R.id.pager);
    final ImageView background = ButterKnife.findById(this, R.id.scrolling_background);
    int[] screenSize = screenSize();

    for (ImageView element : sharedElements) {
      @ColorRes int color = element.getId() != R.id.logo ? R.color.white_transparent : R.color.color_logo_log_in;
      DrawableCompat.setTint(element.getDrawable(), ContextCompat.getColor(this, color));
    }

authfragment

{
    public abstract class AuthFragment extends Fragment {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
      }
      protected Callback callback;
    
      @BindView(R.id.caption)
      protected VerticalTextView caption;
    
      @BindView(R.id.root)
      protected ViewGroup parent;
    
      protected boolean lock;
    
    
    
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(authLayout(), container, false);
        ButterKnife.bind(this, root);
        KeyboardVisibilityEvent.setEventListener(getActivity(), isOpen -> {
          callback.scale(isOpen);
          if (!isOpen) {
            clearFocus();
          }
        });
        return root;
      }
    
      public void setCallback(@NonNull Callback callback) {
        this.callback = callback;
      }
    
      @LayoutRes
      public abstract int authLayout();
    
      public abstract void fold();
    
      public abstract void clearFocus();
    
      @OnClick(R.id.root)
      public void unfold() {
        if (!lock) {
          caption.setVerticalText(false);
          caption.requestLayout();
          Rotate transition = new Rotate();
          transition.setStartAngle(-90f);
          transition.setEndAngle(0f);
          transition.addTarget(caption);
          TransitionSet set = new TransitionSet();
          set.setDuration(getResources().getInteger(R.integer.duration));
          ChangeBounds changeBounds = new ChangeBounds();
          set.addTransition(changeBounds);
          set.addTransition(transition);
          TextSizeTransition sizeTransition = new TextSizeTransition();
          sizeTransition.addTarget(caption);
          set.addTransition(sizeTransition);
          set.setOrdering(TransitionSet.ORDERING_TOGETHER);
          caption.post(() -> {
            TransitionManager.beginDelayedTransition(parent, set);
            } 

pls help me fix this error with butterknife . findbyid isnt also not available not able to use bindview pls help out with documentation or your code. so thats the authFragment now after some changes as suggested by GermliShx these error came maybe it my implementation error so pls help me out. this is the login page with some animation idk y butterknife is creating problem her . i tried solving it but no luck this error is due to wrong implementation of butter knife so pls hel me out

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First remove this:

    @BindViews({R.id.pager)
    @BindViews(R.id.scrolling_background)
... 
final AnimatedViewPager pager = ButterKnife.findById(this, R.id.pager);
    final ImageView background = ButterKnife.findById(this, R.id.scrolling_background);

Second add this:

    public class LoginActivity extends AppCompatActivity {
        ...
       //binding is declared outside OnCreate / any other function

       //your case
        @BindView(R.id.pager)
            AnimatedViewPager pager;
            @BindView(R.id.scrolling_background)
            ImageView background ;

        ..
        //then in code just use declared pager and background when needed 
         @Override
          protected void onCreate(Bundle savedInstanceState) {
              background .setColorFilter (R.color.black); //example 
        }

Should work, but I am not sure what AnimatedViewPager is.

It also may show Resource IDs will be non-final in Android Gradle Plugin version 7.0, avoid using them as annotation attributes warning, but you can just suppress it.

Try and reply how is it going.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...