Tag: anko

anko doAsync onComplete

我知道有两种方法可以在Anko库中执行AsyncTask 。 doAsync() doAsyncResult() 我的问题是上面的方法都有onComplete()方法。 在这两个方法的onComplete()中都没有像AsyncTask.onPostExecute()这样的结果跟踪。 例如 : doAsync { sdkServiceFactory.initSDKService() onComplete { Log.d("Controller", "Sdk Connected") } } val result = doAsyncResult { onComplete { Log.d("Controller", "Sdk Connected") } sdkServiceFactory.initSDKService() }.get() 在任何一种方法中,我只能得到完成的回调而不是结果。 Anko库中用于AsyncTask.onPreExecute()和AsyncTask.onPostExecute()的类似方法有哪些。

使用Anko获取类型不匹配错误需要AnkoContext <ViewGroup>找到AnkoContext <Context>

我在一个基本的Android应用程序中使用Anko,在那里我正在实施recyclerView。 在onCreateViewHolder()方法中,我得到一个编译时错误,说类型不匹配。 下面的代码中的其他一切都很好。 class ListAdapter(val arrayList: ArrayList<String> = ArrayList<String>()) : RecyclerView.Adapter<Holder>() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder? { //type Mismatch error required AnkoContext<ViewGroup> Found AnkoContext<Context> return Holder(ItemUI().createView(AnkoContext.create(parent!!.context))) } override fun onBindViewHolder(holder: Holder, position: Int) { val item = arrayList.get(position) holder.bind(item) } override fun getItemCount(): Int { return arrayList.size } } class ItemUI : […]

安口。 运行异步布局修改

我正在尝试使用anko将按钮添加到我的活动中。 我知道有可能使用RxJava(我已经这样做了)。 我想知道如何使用Anko和异步。 代码在同步线程上运行时工作。 class MainActivity : AppCompatActivity() { fun someMethod(){ async(UI) { bg { var button = Button(this@MainActivity) button.background = this@MainActivity.getDrawable(R.drawable.ic_action_balloon) myFrame.addView(button) } } } 当我构建代码时,我得到这个错误: 错误:(32,17)Val不能被重新分配 错误:(32,55)未解决的引用:getDrawable

使用AnkoLogger级别以外的“信息”

我在我的Android项目中使用AnkoLogger ,但它只适用于日志级别是info ,其他级别什么都不记录,但内置的Android Log效果很好。 我能做些什么来使用AnkoLogger作为内置的替代品?

RecycleView列表项目不出现

我一直在尝试使RecyclerView在我的应用程序中工作,其中的列表项是ImageView ,并且图像被下载并放入(异步)在onBindViewHolder方法中。 我没有在我的代码中遇到任何错误,但出于某种原因 只有在活动加载时才会显示(甚至部分)给用户的列表项,将图像加载到其中。 虽然我看不到图像,但我发现这些项目的高度和宽度已经正确分配。 而且由于图像首先下载,然后确定ImageView的尺寸,我认为这个问题与RecyclerView本身有关系吗? 如果有人能够对此有所了解,那就太好了。 谢谢。 我还想补充一点,如果活动暂停,然后恢复(通过单击“方形”导航按钮,然后恢复),所有列表项的图像加载正确。 图#1 图#2 这是我的代码: onCreate方法: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) recyclerView { id = ViewID.ID_LIST } val imgList = ArrayList<ImageView>() imgList.add(ImageView(ctx)) imgList.add(ImageView(ctx)) imgList.add(ImageView(ctx)) imgList.add(ImageView(ctx)) val lv = findViewById(ViewID.ID_LIST) as RecyclerView lv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) lv.adapter = ImageRecyclerAdapter(ctx, imgList) } RecyclerView.Adapter类: private class ImageRecyclerAdapter(val context: Context, […]

android anko alert自定义布局currentFocus

我有一个包含EditText的自定义布局的警报视图 activity.alert { var quantityEt: EditText? = null customView { linearLayout { orientation = LinearLayout.VERTICAL quantityEt = editText {} quantityEt!!.requestFocus() Log.e("LOL", ac.window.currentFocus.toString()) } } }.show() 那么我请求关注这个编辑文本。 但是, activity.window.currentFocus输出currentFocus android.support.v7.widget.RecyclerView。 我需要currentFocus是EditText。 我也尝试点击它来请求重点,但仍然得到了RecyclerView。 有没有办法做到这一点?

如何在Anko上使用selectableButtonBackground?

如何在像下面的结构一样的构造函数中使用Anko的apply()方法的自定义View上使用selectableButtonBackground属性? class XPTO(context: Context) : CardView(context) { init { this.apply { // I'd like to invoke selectableButtonBackground here } } 我试图做context.obtainStyledAttributes(arrayOf(R.attr.selectableItemBackground).toIntArray()).getDrawable(0)但没有成功。

在anko DSL中相当于<fragment>标签

如何用Anko DSL等价物替换这个XML? <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> // more code here…. <fragment android:id="@+id/my_fragment" android:layout_width="340dp" android:layout_height="match_parent" android:layout_gravity="start" android:name="com.myapp.MyFragment" /> // more code here…. </LinearLayout> 安科版本: UI { linearLayout { orientation= VERTICAL fragment { // error! name = "com.myapp.MyFragment" } }.lparams(width=…, height=…) } 似乎没有eqiuvalen在DSL中的片段标签。 谢谢!

如何在anko中为按钮设置图标(可绘制)?

我想用简单的按钮在一个普通的按钮的中心有一个图标。 我试过了 button.backgroundResource = R.drawable.arrow_forward 但我得到的可绘制覆盖整个按钮,并获得其父母的背景颜色(设置按钮上的背景颜色显示不做任何事情)。 我也尝试drawable = … ,同样的效果。 如何设置anko图标,使其具有原始宽高比并居中?

使用Anko获取数据库行

我有一个数据库的Kolin Android应用程序。 我使用Anko库进行数据库通信。 我可以在我的数据库中插入数据,但是当我尝试从数据库中获取数据行时遇到一些麻烦。 我尝试通过以下代码获取数据行 try { var result = select("projects").where("rowid = {id}", "id" to 1).parseList(StringParser) Toast.makeText(applicationContext,result.toString(),Toast.LENGTH_LONG).show() } catch(e: Exception) { Toast.makeText(applicationContext,e.toString(),Toast.LENGTH_LONG).show() } 我怎样才能得到具有给定的ID行的内容 目前我得到这个错误 无效行:SingleColumnParser的行必须只包含一列