我试图将十六进制值转换为int,以便我可以创建一个新的颜色drawable.我不确定这是否可行,但根据文档,它应该.它显然要求
public ColorDrawable(int color)
在API级别1中添加创建具有指定颜色的新ColorDrawable.
参数 color 要绘制的颜色.
所以,我的代码不起作用,因为我得到一个无效的int:"FF6666"错误.有任何想法吗?
int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);
Run Code Online (Sandbox Code Playgroud) 我允许我的用户在我的应用中为通知选择铃声.我想存储声音的URI以及人类可读的声音标题.
到目前为止,URI代码非常有用:
Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
Run Code Online (Sandbox Code Playgroud)
但是当我试图获得标题并将其设置为按钮文本时,我什么也得不到.好像没有头衔?
String title = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
button.setText(title);
Run Code Online (Sandbox Code Playgroud)
但我的按钮文字是空的.如果我做:
button.setText(uri.toString());
Run Code Online (Sandbox Code Playgroud)
然后我完全看到了uri.我应该尝试从URI获取标题吗?谢谢
我知道在stackoverflow上发布了很多类似的问题,所以请不要认为我没有搜索到高低.我认为我的问题只是从现在完全理解listViews和列表项的生命周期.我有一个列表视图,可以包含两种类型的消息,出站或入站.最初,我的listView将使用不同的背景颜色,具体取决于消息的类型(出站与入站),并且它可以完美地工作.现在我的应用程序不需要列表项的不同背景,但它实际上需要不同的列表项的不同布局.
这是我的适配器的剪辑.
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
SoapBoxMessage thisMessage = messages.get(position);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (thisMessage.isOutbound()) {
v = inflater.inflate(R.layout.outbound_row, null);
} else {
v = inflater.inflate(R.layout.inbound_row, null);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用commonsware相机库.我的照片看起来很棒,但当我接近我要重新聚焦的东西时,我却无法做到这一点.我已经按照这里看到的一些read me文档:
您可以在CameraFragment或CameraView上调用autoFocus()来触发您在Camera.Parameters上通过setFocusMode()配置的任何自动对焦行为.您可以在CameraFragment或CameraView上调用cancelAutoFocus()以确保已取消自动对焦模式.
我只是在屏幕上做一个onclicklistener,并希望它再次聚焦,以便我的图片清晰.有没有人成功这样做过?
我有(我认为的)一个非常简单的概念,我可以在其中刷新待办事项列表的详细信息。我发现,如果有足够的 TODO 项目(几千个)并且按下刷新按钮(因此fetchFreshTodoItemDetails重复调用),那么我会因以下异常而崩溃:
java.util.ConcurrentModificationException
at androidx.compose.runtime.snapshots.StateListIterator.validateModification(SnapshotStateList.kt:278)
at androidx.compose.runtime.snapshots.StateListIterator.next(SnapshotStateList.kt:257)
at com.rollertoaster.app.ui.screens.todo.TodoScreenViewModel$fetchFreshTodoItemDetails$1$1$1.invokeSuspend(TodoScreenViewModel.kt:332)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@97be452, Dispatchers.Main.immediate]
Run Code Online (Sandbox Code Playgroud)
我的视图模型:
java.util.ConcurrentModificationException
at androidx.compose.runtime.snapshots.StateListIterator.validateModification(SnapshotStateList.kt:278)
at androidx.compose.runtime.snapshots.StateListIterator.next(SnapshotStateList.kt:257)
at com.rollertoaster.app.ui.screens.todo.TodoScreenViewModel$fetchFreshTodoItemDetails$1$1$1.invokeSuspend(TodoScreenViewModel.kt:332)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@97be452, Dispatchers.Main.immediate]
Run Code Online (Sandbox Code Playgroud)
尽管我可以想出几种方法来解决这个问题...我仍然“认为”上述方法应该有效,但事实并非如此,这让我有点疯狂。感谢任何帮助。谢谢
编辑: fullListOfTodos 在我的 appStateHolder 中定义
var fullListOfTodos = mutableStateListOf<TodoModel>()
我有一个web.properties包含一堆键值的文件.
FIRST="true"
SECOND="true"
THIRD="true"
Run Code Online (Sandbox Code Playgroud)
我正在编写一个bash脚本来显示web.properties文件中的所有键
myscript.sh
file="web.properties"
if [ -f "$file" ]; then
echo "file found"
while IFS='=' read -r key value
do
echo "Found ${key}"
done < "$file"
else
echo "$file not found."
fi
Run Code Online (Sandbox Code Playgroud)
输出:
FIRST
SECOND
Run Code Online (Sandbox Code Playgroud)
如你所见,THIRD被遗漏了.如果我修改我的web.properties文件以获得额外的回报
web.properties
FIRST="true"
SECOND="true"
THIRD="true"
//stackoverflow doesn't allow me to do an empty line in code formatting, so pretend this doesn't exist
Run Code Online (Sandbox Code Playgroud)
我的输出是:
FIRST
SECOND
THIRD
Run Code Online (Sandbox Code Playgroud)
我希望我的bash脚本能够在两种情况下工作,因为文件是以编程方式和手动方式编辑的,因此IDE可能有也可能没有该尾随空格.使用尾随回车或没有它.思考?