butterknife

Remove “Method is never used” warning for OnClick annotation in Android Studio

情到浓时终转凉″ 提交于 2019-11-30 10:44:00
Sorry if this question has been asked before. I am using the Butterknife 5.0 with the latest version of Android Studio(0.5.7). How can I remove the "Method is never used" warning for methods that use the 'OnClick' Annotation of ButterKnife.I noticed that Eclipse doesnt give this warning for the 'OnClick' methods. Thanks in advance The correct way in Android Studio to suppress these warnings is to press Alt+Enter on the method giving the Method 'yourFunction()' is never used warning, and selecting Suppress for methods annotated by 'butterknife.OnClick' Simply add this annotation:

ButterKnife onclick is not working

久未见 提交于 2019-11-30 06:39:15
I injected views perfectly using butterknife library. But when I try to implement listeners, for example onclick I'm not able to implement them. Following java code will help you to understand my problem. Java code: public class LoginActivity extends ActionBarActivity{ @InjectView(R.id.toolbar) Toolbar toolbar; @InjectView(R.id.btn_login) Button login; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); ButterKnife.inject(this); initialize(); //initListeners(); @OnClick(R.id.btn_login) public void submit(View view)

Android注解的理解与使用

南笙酒味 提交于 2019-11-30 03:47:12
为什么是注解 作为 Android 开发人员,先看一些熟悉的代码: setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.xxx, parent, false))); 像这样的不可省略代码,大量出现在各个地方,一遍一遍的被复制,复制过程中改变很少,或者根本没有改变。在计算机编程中称之为 样板代码 。经常使用类似的 样板 ,直接后果导致程序员编写更多代码,做更少的工作。这显然是不可以忍受的。 从 《重构改善既有代码的设计》章节三:代码的坏味道 中,我们学到,多个相同的程序结构,将他们合二为一,程序会变得更好。最直观体现就是使用工具类抽取公共方法各处调用。这样就可以更少的代码,更高的效率了。类似的,使用注解解决 Android 中的样板代码问题。 上面的引子的目的是要直观地说明,为什么需要注解?术语话一些如下: > 每当你创建描述符性质的类和接口的时,一旦其中包含重复性工作,就可以考虑简化与自动化该过程。 > 如果你想为应用设置很多的常量或参数,xml是一个很好的选择,因为它不会同特定的代码相连。如果你想把某个方法声明为服务

Gradle DSL method not found: 'apt()'

大兔子大兔子 提交于 2019-11-30 02:41:07
I am trying to add the latest version of butterknife and I get this error from gradle: Error:(31, 0) Gradle DSL method not found: 'apt()' Possible causes: The project 'MyProject' may be using a version of Gradle that does not contain the method. Gradle settings The build file may be missing a Gradle plugin. Apply Gradle plugin Where my gradle mobile build.gradle is: plugins { id "net.ltgt.apt" version "0.6" } apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.mynamspace.myproject" minSdkVersion 19

Dagger2 探索记1——四大基本组件(一)

被刻印的时光 ゝ 提交于 2019-11-30 02:21:03
和很多自主学习的人,我接触Dagger 2 框架的原因是刚进公司的时候导师给安排的学习任务,学习方式是组内培训。 听到这个消息的我,以为是部门的人轮流给我讲课。 后来导师跟我说,组内培训的意思是,我先自己好好学这个框架,然后给组内的所有人搞个培训。 没办法,在网上看了很多相关博客,浪费了不少时间,终于还是学有所得,也记录一下我最近的学习进展。 就不多讲什么历史了,你能看到我这篇博客,想来历史什么的科普你都已经被塞到吐了,还是撸代码学得快。 一 环境配置 在module的build.gradle中添加代码: dependencies { ...... //dagger2 implementation 'com.google.dagger:dagger:2.7' annotationProcessor 'com.google.dagger:dagger-compiler:2.7' //butterknife implementation 'com.jakewharton:butterknife:10.0.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0' } 为了后面书写代码简便,将ButterKnife一起配置了。 在Project build.gradle中添加如下代码

Butterknife Fragment Button not working

只愿长相守 提交于 2019-11-30 01:24:39
问题 I have a Fragment that I am using Butterknife with. 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 } } However, the someButtonOnClick method is never called when the button is tapped on the screen. Thoughts

Butterknife View injection

匆匆过客 提交于 2019-11-30 01:07:27
问题 I stumbled across a very interesting Dependency Injection library called ButterKnife . Using ButterKnife it's easily possible to inject Views into activities or fragments. class ExampleActivity extends Activity { @InjectView(R.id.title) TextView title; @InjectView(R.id.subtitle) TextView subtitle; @InjectView(R.id.footer) TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.inject

Android组件化架构学习笔记——组件化编程之静态变量/资源/混淆/多渠道打包

廉价感情. 提交于 2019-11-29 11:24:06
一.组件化的静态变量: R.java的生成: 各个module会生成aar文件,并且被引用到Application module中,最终合并为apk文件。当各个次级module在Application module中被解压后,在编译时资源R.java会被重新解压到build/generated/source/r/debug(release)/包名/R.java中。 当每个组件中的aar文件汇总到App module中时,也就是编译的初期解析资源阶段,其每个module的R.java释放的同时,会检测到全部的R.java文件,然后通过合并,最后合并成唯一的一份R.java资源。 R2.java及 ButterKnife : ButterKnife 是一个专注于Android View的注入框架,可以大量的减少findViewById和setOnClickListener操作的第三方库。 注解中只能使用常量,如不是常量会提示attribute value must be contant的错误。可以在使用替代方法,原理是将R.java文件复制一份,命名为R2.java。然后给R2.java变量加上final修饰符,在相关的地方直接引用R2资源。 如项目中已经使用 ButterKnife 维护迭代了一段时间,那么使用R2.java的方案适配成本是最低的。

Android-打包AAR步骤以及最为关键的注意事项!

て烟熏妆下的殇ゞ 提交于 2019-11-29 09:33:52
简介 最近因为项目的要求,需要把开发的模块打包成aar,供其他项目调用,在搞了一段时间后,发现这里还是有很多需要注意的地方,所以记录一下,帮助大家不要走弯路。 首先何为aar包? jar与aar的简单区别: *.jar:只包含了class文件与清单文件 ,不包含资源文件,如图片等所有res中的文件。 *.aar:包含所有资源 ,class 以及 res 资源文件全部包含 新工程(无依赖)打包AAR的步骤 1.新建Library 然后一路next+finish就新建成功了 将要打包的文件都按照文件夹的位置放入你的Module中,然后直接点击build-->Make Moudle app 打包成功后会在对应的路径下生成aar 当然了,这些应该应该都不是我们需要的, 因为开发项目中一定会有所依赖的。 而且也肯定不是空的项目。 成型的项目(有依赖)如何快速打包AAR 我们可以直接在项目中New一个Moudle 然后把项目复制到Moudle中,或者重新复制出来一个当前项目,然后在复制的项目中直接把此项目修改成AAR。 我就说一下第二种把,也就是把复制项目直接修改成AAR,我们需要做如下改动: 1. 修改app下的bulid gradle文件: 把apply plugin: 'com.android.application'修改成apply plugin: 'com.android

ButterKnife onclick is not working

一曲冷凌霜 提交于 2019-11-29 05:35:53
问题 I injected views perfectly using butterknife library. But when I try to implement listeners, for example onclick I'm not able to implement them. Following java code will help you to understand my problem. Java code: public class LoginActivity extends ActionBarActivity{ @InjectView(R.id.toolbar) Toolbar toolbar; @InjectView(R.id.btn_login) Button login; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); ButterKnife