我正试图围绕视图,听众等.我有一个带有2个按钮的活动:按钮和按钮停止.我的问题是我无法完全绕过Views和Listener来生成一个有效的switch语句.
例如,我想创建一个SINGLE Listener并以某种方式使用它来确定单击了哪个按钮.然后以某种方式使用我的switch语句点击按钮的ID,但是,一切都我在网上找似乎使用单独的侦听器为每个按钮,然后以某种方式使用该视图作为参数传递给switch语句.
我意识到下面的代码不正确,但我正在寻找完成上述操作所需的更改.
我想根据点击的按钮来控制MediaPlayer.我有:
Button b1 = (Button) findViewById(R.id.buttonplay);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
// Perform action on click
switch(v.getId()) {
case R.id.buttonplay:
//Play voicefile
MediaPlayer.create(getBaseContext(), R.raw.voicefile).start();
break;
case R.id.buttonstop:
//Stop MediaPlayer
MediaPlayer.create(getBaseContext(), R.raw.voicefile).stop();
break;
}
}
});
Run Code Online (Sandbox Code Playgroud)
最终,我希望以最直接的方式打开点击的任何按钮.我相信我的困惑很大一部分源于在此上下文中使用onClickListeners和Views的方式.
}
我希望制作一个可以从列表中添加和删除的项目。
我正在寻找的是具有 + 图标和 - 图标并在 2 之间设置动画以获得干净流畅的外观。
我有以下代码
Container(
padding: EdgeInsets.fromLTRB(0, 0, 20, 0),
child: AnimatedIcon(
icon: AnimatedIcons.home_menu,
progress: _animationController,
color: Colors.white,
))
Run Code Online (Sandbox Code Playgroud)
和
void _handleOnPressed() {
setState(() {
isPlaying = !isPlaying;
isPlaying
? _animationController.forward()
: _animationController.reverse();
});
}
Run Code Online (Sandbox Code Playgroud)
这对于颤振中的内置动画图标来说很好。
我希望使用 + 和 - 图标,但外观相同。
有没有办法做到这一点?
我们如何动态添加视图并动态androidx.constraintlayout.helper.widget.Flow
添加引用 ID。
应用签名证书和上传证书有什么区别?我在将 Google Play 游戏与我的应用程序集成时遇到问题(我将此作为另一个问题发布),并且我注意到用于在 Google API 控制台上自动生成的客户端 ID 的证书称为签名证书。
但是,当我在 Android Studio 上运行登录报告时看到的内容称为上传证书。
client Id 应该设置哪一个?顺便说一句,两者都没有解决我的问题,但我很好奇其中的区别。
我有一个根标签为
androidx.constraintlayout.widget.ConstraintLayout
Run Code Online (Sandbox Code Playgroud)
我在此活动中包含 3 个布局文件并垂直列出它们。以下对中间的约束不起作用
app:layout_constraintTop_toBottomOf="@+id/lay1"
app:layout_constraintBottom_toTopOf="@+id/lay3"
Run Code Online (Sandbox Code Playgroud)
我不明白为什么中间一个占据整个屏幕而不是从顶部的底部开始并在底部的顶部结束。你能帮我么?
活动:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/lay1"
layout="@layout/empty_linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/lay2"
layout="@layout/empty_linear_layout"
app:layout_constraintBottom_toTopOf="@+id/lay3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lay1" />
<include
android:id="@+id/lay3"
layout="@layout/empty_linear_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
empty_linear_layout.xml :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我想知道如何将项目发送/发送到Kotlin.Flow
,所以我的用例是:
在消费者/ ViewModel / Presenter中,我可以使用以下 功能进行订阅collect
:
fun observe() {
coroutineScope.launch {
// 1. Send event
reopsitory.observe().collect {
println(it)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是问题就在Repository
侧面,对于RxJava,我们可以使用BehaviorBehavior主题将其公开为Observable/Flowable
并发出类似以下的新项:
behaviourSubject.onNext(true)
Run Code Online (Sandbox Code Playgroud)
但是,每当我建立新流程时:
flow {
}
Run Code Online (Sandbox Code Playgroud)
我只能收集。如何将值发送到流?
android kotlin kotlin-coroutines kotlinx.coroutines.channels kotlinx.coroutines.flow
在 CardView 中使用圆角时,在圆角区域显示白色边框,这在黑暗环境中最常见。为了更容易理解,请检查附加的图像吹。
这是 xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorTransparent"
android:orientation="vertical"
android:padding="4sp">
<androidx.cardview.widget.CardView
android:id="@+id/image_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:background="@color/colorTransparent"
app:cardCornerRadius="20dp"
app:cardElevation="4dp">
<ImageView
android:id="@+id/iv_themes"
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@color/colorTransparent"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@mipmap/tm_2_mip_background" />
</androidx.cardview.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我刚刚将我的 android studio 升级到 4.1 版本:
并尝试在此模拟器上运行一些项目:
出于某种原因,这个特定的模拟器使我的 android studio 崩溃了,我注意到我收到了一个错误:
阅读有关主题后,我卸载了“Riot Vanguard”,但它并没有解决我的问题。
更多信息(和部分解决问题)可以在问题底部的“更新”中找到。
此外,在我的 android studio 关闭后不久,我会看到一个 Windows 蓝屏(每次都会发生)。
我之前在 4.1 版本以下的 android studio 中没有这个问题,为什么会发生这种情况?
我在其他模拟器上也遇到了同样的问题,但我可以打开这些模拟器来解决这个问题:
根据我遇到的大多数线程,您需要禁用或卸载“Riot Vanguard”:
打开任务管理器,转到启动选项卡,右键单击 Riot Vanguard,然后按禁用
如果步骤 1 没有解决问题,您可能需要在模拟器上启用开发人员模式。
出于某种原因,android studio 4.1 android studio 找不到模拟器(它会告诉你没有启用开发者模式)
在 Android studio 4.1 版本之前,我不需要启用开发者模式在模拟器上运行项目,这就是为我解决其他模拟器问题的原因。
尽管我对其他模拟器完全没有任何问题,但我仍然无法在 不崩溃的情况下打开 Pixel_3a_API_30c68 模拟器
如何在特定模拟器上解决此问题?
即使将android studio更新到4.1.1后问题仍然存在
当创建新的应用程序并在Use Android X artifacts
不做任何修改的情况下检查时,应用程序在我的手机和模拟器上崩溃。
我已要求我的朋友重复创建应用程序的方法,并且手机中的所有功能都可以正常工作。
这是我第一次使用Android X,我做错什么了吗?我正在快速运行Android Studio 3.3.0.20(Linux)。
2019-02-08 17:54:44.477 5487-5487/worshifter.com.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: worshifter.com.myapplication, PID: 5487
java.lang.RuntimeException: Unable to start activity ComponentInfo{worshifter.com.myapplication/worshifter.com.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line …
Run Code Online (Sandbox Code Playgroud) 在主要、次要和仲裁者的复制设置中,复制连接 URI 间歇性超时,日志显示以下错误。请帮助分享可能是什么问题以及建议的修复方法是什么。
NetworkInterfaceExceededTimeLimit: error in fetcher batch callback ::
caused by :: timed out. Last fetched optime (with hash): { ts:
Timestamp(1554364591, 71), t: 65596 }[3697357721798898959]. Restarts
remaining: 1 I REPL [replication-1] Error returned from oplog
query (no more query restarts left): MaxTimeMSExpired: error in
fetcher batch callback :: caused by :: operation exceeded time limit W
REPL [rsBackgroundSync] Fetcher stopped querying remote oplog with
error: MaxTimeMSExpired: error in fetcher batch callback :: caused by
:: operation exceeded time …
Run Code Online (Sandbox Code Playgroud) android ×8
androidx ×1
button ×1
constraints ×1
dart ×1
flutter ×1
kotlin ×1
kotlinx.coroutines.channels ×1
listener ×1
mongodb ×1
replication ×1
xml ×1