我想从泛型类型获取类属性T.我决定延伸到Any但是我收到了一个错误.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html#extension-properties
我有以下代码:
class FirebaseDBRepo<T : Any>(val child:String) {
private var callback: FirebaseDatabaseRepositoryCallback<T>? = null
private val ref: DatabaseReference
private val listener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
//T::class.java is showing the error cannot use t as reified type parameter use class instead
val gameDS = dataSnapshot.getValue(T::class.java)
callback!!.onSuccess(gameDS!!)
}
override fun onCancelled(databaseError: DatabaseError) {
}
}
init {
ref = FirebaseDatabase.getInstance().reference.child(child)
}
fun addListener(callback: FirebaseDatabaseRepositoryCallback<T>) {
this.callback = callback
ref.addValueEventListener(listener)
}
fun …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 material.io 测试 BottomAppBar 功能。但是,当我尝试运行应用程序时,我会立即崩溃:
> 10-20 22:21:25.067 27571-27571/com.example.asmox.bcl E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.asmox.bcl, PID: 27571
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asmox.bcl/com.example.asmox.bcl.ViewActivity}: android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class android.support.design.bottomappbar.BottomAppBar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #33: Binary XML file line #33: Error inflating class android.support.design.bottomappbar.BottomAppBar
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) …Run Code Online (Sandbox Code Playgroud) 我在launchMode SingleInstance中有几个活动.注销时我想完成所有活动并打开launchScreen.
val intent = Intent(context, LauncherActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
(context as AppCompatActivity).finishAffinity()
context.startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
但是,如果我按回Launcher活动,我会转发到以前启动的具有singleInstance模式的活动
我正在开发一个上载大量数据的应用程序。我想确定上传的传输速率,以显示在通知中。
我对这些帖子中的答案不满意,因此我再次询问。
我看过显示上传传输速率的应用程序,以及一些自定义ROM,例如Resurrection Remix。
如何确定这些上传的传输速率?
我尝试在我的应用中实现导航功能。当我尝试构建应用程序时,输出显示:
Android resource linking failed
/home/mateusz/AndroidStudioProjects/TakeAndTie/app/src/main/res/layout/activity_main.xml:23: error: attribute defaultNavHost (aka com.mateuszpolito.takeandtie:defaultNavHost) not found.
/home/mateusz/AndroidStudioProjects/TakeAndTie/app/src/main/res/layout/activity_main.xml:23: error: attribute navGraph (aka com.mateuszpolito.takeandtie:navGraph) not found.
error: failed linking file resources.
Run Code Online (Sandbox Code Playgroud)
这是 activity_main.xml 中的 nav_host_fragment:
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
Run Code Online (Sandbox Code Playgroud)
我已经在我的应用级 build.gradle 中实现了导航:
implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha02"
Run Code Online (Sandbox Code Playgroud)
我使用的是 Android Studio 3.4 版
webpack和npm有什么区别?我应该同时使用它们吗?使用webpack和npm的优点和缺点是什么?更喜欢哪一个呢?懂了npm还有必要学webpack吗?
我正在为已经完成的应用程序提供阿拉伯语支持。将应用程序语言更改为阿拉伯语时,数字将显示为 XML 字符串的阿拉伯数字。
\n但我的问题是执行以下代码
\ngetString(R.string.value, ++value);\nRun Code Online (Sandbox Code Playgroud)\n价值观
\n<string name="value">Value : %d</string>\nRun Code Online (Sandbox Code Playgroud)\n价值观-ar
\n<string name="value">%d :\xd8\xa7\xd9\x84\xd9\x82\xd9\x8a\xd9\x85\xd8\xa9 </string>\nRun Code Online (Sandbox Code Playgroud)\n有了英语,它就可以正常工作。
\nValue: 1\nRun Code Online (Sandbox Code Playgroud)\n关于将语言更改为阿拉伯语(以阿拉伯语出现)。必须是英语 (0-9)
\nValue : (Number in Arabic)\nRun Code Online (Sandbox Code Playgroud)\n请为我的问题提供解决方案。
\nFlow我对使用withRoom进行数据库访问感到困惑。我希望能够观察表的变化,同时也可以直接访问它。但是,当使用返回 a 的查询时Flow,结果似乎总是这样null,尽管表不为空。直接返回 a 的查询List似乎有效。
有人可以解释其中的差异或告诉我我可能错过了文档的哪一部分吗?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
db_button.setOnClickListener {
val user_dao = UserDatabase.getInstance(this).userDatabaseDao
lifecycleScope.launch {
user_dao.insertState(State(step=4))
val states = user_dao.getAllState().asLiveData().value
if (states == null || states.isEmpty()) {
println("null")
} else {
val s = states.first().step
println("step $s")
}
val direct = user_dao.getStatesDirect().first().step
println("direct step $direct")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
@Entity(tableName = "state")
data class State(
@PrimaryKey(autoGenerate = true)
var id: …Run Code Online (Sandbox Code Playgroud) 第一次recyclerView加载时会显示一切正常。但滚动后,布局项目大小发生了变化。

这是我的item_layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/item_border"
android:layout_margin="@dimen/item_margin_2">
<ImageView
android:id="@+id/imageProduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@+id/textProductTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="@dimen/title_textSize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageProduct"
tools:text="TubeLight" />
<TextView
android:id="@+id/textProductDetailSort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@android:color/black"
android:textSize="@dimen/detail_textSize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textProductTitle"
tools:text="warranty: 100 days" />
<LinearLayout
android:id="@+id/linerCartItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textProductDetailSort">
<ImageButton
android:id="@+id/buttonRemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/item_border_small"
android:src="@drawable/ic_outline_remove_24"/>
<TextView
android:id="@+id/textNumberItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryLight"
android:textSize="@dimen/detail_small_textSize"
android:padding="@dimen/item_padding"
android:textColor="@color/black"
android:layout_margin="@dimen/item_margin_3"
android:text="0"/>
<ImageButton
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/item_border_small"
android:src="@drawable/ic_baseline_add_24"/>
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) android android-layout android-imageview kotlin android-recyclerview