我在我的Android项目中使用Dagger 2,但我在调试时遇到问题.我知道编译失败是因为我的匕首2设置中的错误(以前有过)但是几乎不可能跟踪它,因为我没有得到正确的错误消息告诉我问题出在哪里.我得到的只是显示注释处理失败的消息.沿着:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(14, 28) error: cannot find symbol class BR
Error:(17, 40) error: package com.some.package.databinding does not exist
Error:(17, 51) error: cannot find symbol class DaggerSomeComponent
...
Run Code Online (Sandbox Code Playgroud)
也许它与某些事实有关,我也在使用数据绑定!?
我正在使用Dagger 2.5,Gradle插件2.1.2和android-apt 1.8.
谢谢你的帮助!
android annotation-processing dagger-2 android-databinding kapt
我正在尝试使用新的Android Lollipop API setButtonTintList()
以编程方式将颜色应用于android CheckBox
es.
我已经设置了以下基本ColorStateList
在checkbox_color.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:color="@color/red" />
<item android:state_checked="false"
android:color="@color/green" />
</selector>
Run Code Online (Sandbox Code Playgroud)
Button
在我的应用程序中的特定点击我膨胀一个新的布局,其中包含一个CheckBox
到我的主布局(mLayoutTotalItemRow
)通过:
View itemRow = getActivity().getLayoutInflater().inflate(R.layout.row_add_purchase, mLayoutTotalItemRow, false);
Run Code Online (Sandbox Code Playgroud)
通胀后,我想申请checkbox_color.xml
新的CheckBox
通道(我想在代码而不是xml中执行此操作的原因是我想根据一些变量设置不同的颜色):
mCheckBoxEnabled.setButtonTintList(mContext.getResources().getColorStateList(R.color.checkbox_color));
Run Code Online (Sandbox Code Playgroud)
现在出现一个奇怪的事情,当CheckBox
它第一次创建时,它是红色的(因此state_checked="true"
.一旦我取消选中它,它就是绿色(state_chacked="false"
).但是当我现在再次检查它时,它会变为勾选但它保持绿色!因此不知何故内部视图状态未更改为"已检查".
我的复选框xml:
<CheckBox
android:id="@+id/cb_item_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/key_line_1_minus_checkbox_margin"
android:layout_marginEnd="@dimen/key_line_2_minus_key_line_1_minus_checkbox"
android:layout_gravity="center_vertical"
android:checked="true"/>
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么想法?
Afaik,在Java中,匿名内部类总是拥有对其外部类的封闭实例的引用.现在当我在静态方法中放入一个匿名类时会发生什么?由于它的外部类没有对象,它是否包含对调用静态方法的类的引用?我在这里有点困惑.考虑下面的Android示例(使用parse.com框架):
public class OnlineQuery {
public static void queryUsers(final ListenerInterface listener) {
ParseQuery<ParseUser> query = User.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(final List<ParseUser> userList, ParseException e) {
listener.reportBackToCallingActivity();
// to which class is as a reference held here?
}
});
}
}
public class MainActivity extends Activity implements OnlineQuery.ListenerInterface {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnlineQuery.queryUsers(this)
}
...
}
Run Code Online (Sandbox Code Playgroud)
另外,正在使用一个监听器,如示例中关于内存泄漏的错误做法所示?谢谢!
java android static-methods memory-leaks anonymous-inner-class