具有添加片段和后续replace()
片段的流程。所有片段都被动态添加,但并非所有call都被添加addToBackStack()
。
getSupportFragmentManager().beginTransaction()
.add(R.id.frgment_holder, frgmtA, frgmtA.NAME)
.commit();
Run Code Online (Sandbox Code Playgroud)
在某个地方可以添加另一个,例如:
getSupportFragmentManager().beginTransaction()
.replace(R.id.frgment_holder, frgmtB)
.addToBackStack(frgmtB.NAME)
.commit();
Run Code Online (Sandbox Code Playgroud)
在replace()
与frgmtB将从容器R.id.frgment_holder删除frgmtA。如果在此状态下按返回按钮,则会弹出frgmtB。但是,即使addToBackStack()
添加时未调用它,它也会重新创建frgmtA 吗?
如果在通过序列将片段添加到同一容器的流程中,混合了add()和replace()调用,而有人调用addToBackStack()
但有人不调用,则后退按钮的行为如何?
编辑:之后
getSupportFragmentManager().beginTransaction()
.replace(R.id.frgment_holder, frgmtB)
.addToBackStack(frgmtB.NAME)
.commit();
Run Code Online (Sandbox Code Playgroud)
将
getSupportFragmentManager().findFragmentByTag(frgmtA.NAME);
Run Code Online (Sandbox Code Playgroud)
仍然找到frgmtA?如果在添加frgmtA时也调用addToBackStack()会怎样?
博士说:“这首先搜索当前添加到经理活动中的片段;如果未找到此类片段,则搜索当前堆栈上的所有片段。”
情况将是
(如果frgmtA不是由add()动态添加的,而是在布局文件中使用class =“ frgmtA”分隔的,该怎么办?)
用frgmtB替换(); addToStack();
用frgmtC替换(); addToStack();
那么如果stackTop是frgmtC,则希望按后退按钮以将第一个frgmtA带回其最后一个UI状态。
拥有一款Android房三个用表timestamp
,index
,details
,以及三者有
@PrimaryKey @ColumnInfo(name = "id") var id: Int = 0
Run Code Online (Sandbox Code Playgroud)
必须fun clearDataByID(idList: List<Int>)
通过清除所有三个表id
中的数据idList
道为:
@Dao
interface DataDAO {
@Transaction
fun clearDataByID(idList: List<Int>) {
deleteDataInTimestamp(idList)
deleteDataIndex(idList)
deleteDataDetails(idList)
}
@Query("delete from timestamp where id in :idList")
fun deleteDataInTimestamp(idList: List<Int>)
@Query("delete from index where id in :idList")
fun deleteDataIndex(idList: List<Int>)
@Query("delete from details where id in :idList")
fun deleteDataDetails(idList: List<Int>)
}
Run Code Online (Sandbox Code Playgroud)
但是它会得到编译器错误(这三个都相似)
error: no viable alternative at input 'delete from timestamp where …
Run Code Online (Sandbox Code Playgroud) 最初在屏幕底部显示文本.单击它时,它下面的列表视图应该向上滑动.再次单击文本,列表视图向下滑动.
使其与下面的代码段一起使用,除了第一次单击文本列表不会使动画向上滑动.之后,它将按预期动画上下滑动.
这是因为在第一次点击并调用showListView(true); 由于列表视图的可见性"已消失",因此它没有高度."y"== 0翻译没有做任何事情.它只是将列表视图的可见性更改为"可见",这会推动titleRow更改其位置.
但是如果要从列表视图的可见性开始"可见",则初始showListView(false); 在setupListViewAdapter()中没有将列表视图向下推到初始状态(屏幕底部之外),因为它没有高度,直到列表行由mListView.setAdapter(mListAdapter)从适配器填充.
是否有更好的方法来进行列表视图的上下移动?
<TextView
android:id="@+id/titleRow”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=“title row”
/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility=“gone”
>
</ListView>
initial state list view collapsed(outside screen bottom)
+++++++++++++++++++++++++++
+ mTitleRow + ^ +
+++++ screen bottom +++++
listview expanded
+++++++++++++++++++++++++++
+ mTitleRow + ^ +
+++++++++++++++++++++++++++
+ +
+ mListView +
+ +
+++++ screen bottom +++++
void setupListViewAdapter(){
mTitleRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mTitleRow.getTag() == STATE_COLLAPSED)
{
mListView.setVisibility(View.VISIBLE);
showListView(true);
} else { …
Run Code Online (Sandbox Code Playgroud) 这是注意到的:当它启动时,数据项索引0,1,...,5显示在视图中.并且看到onCreateViewHolder()和onBindViewHolder()被调用了.然后向上滚动顶部项目,并看到onCreateViewHolder()和onBindViewHolder()被调用索引6.然后向下滚动以将项目索引0带回视图.因为它没有被回收所以没有调用onBindViewHolder().
这是设计的,但有一个案例就是要调用onBindViewHolder.
当项目索引0超出视图,并单击视图中的任何项目时,将更改项目索引0的数据.当它滚动回到视图时,想要显示数据的变化.但由于未调用其onBindView,因此不会在UI中更新此行的数据更改.
它可以打电话
notifyDataSetChanged()
Run Code Online (Sandbox Code Playgroud)
数据更改后强制重绘列表.但结果并不好,因为视图项上有图像并显示闪烁.
尝试使用LayoutManager获取强制更新的视图.问题是什么时候知道在LayoutManager的子视图中显示索引0的最佳时间?
有什么建议吗?谢谢!
Using Kotlin to filter a list
var datalist: List<DataType>
val list = datalist.filter {it.Id == currentFilterId}
Run Code Online (Sandbox Code Playgroud)
would like to put in some log to debug the data
val list = datalist.filter {
Log.d(TAG, "$it, currentFilterId: $currentFilterId)
it.postId == currentPostFilterId
}
Run Code Online (Sandbox Code Playgroud)
how to put in multiple lines of statements inside the filter function?
在实现 Parcelable 的类中,它有一个 HashMap 成员。
Saw Parcelable 有
public final void readMap(Map outVal, ClassLoader loader)
,但找不到使用它的样本。
如果通过展平地图并相应地一一写入/读取来完成,如何从构造函数中的包裹中提取?(从parcelable构建地图时出错, cannot access buildTheMap() before constructor is called
)
class CachedData(val type: Int,
val name: String,
val details: HashMap<String, String) :
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readString(),
// how to get the hashMap out of the parcel???
buildTheMap(parcel) //<=== cannot access buildTheMap() before constructor is called
)
fun buildTheMap(parcel: Parcel) :HashMap<String, String> {
val size = parcel.readInt()
val map = HashMap<String, String>() …
Run Code Online (Sandbox Code Playgroud) 在android,kotlin项目中,看到了这个@set:Inject
但找不到很好的解释。有谁知道?
object Controller {
@set:Inject
lateinit var someData: SomeData
Run Code Online (Sandbox Code Playgroud) 有一个包含多个模块的 androidStudio 项目。
prj - 应用插件:'com.android.application',(prj 也是使用 modulA 和 moduleB 的测试应用程序)
模块 A 内部依赖于模块 B。
这些模块将在其他不同的应用项目中用作库。另一个应用程序项目可能依赖于模块 A 或模块 B。
在模块 A 中有一些活动,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oath.module_a">
<application
android:hardwareAccelerated="true"
android:largeHeap="true">
<activity
android:name="com.module_a.LoginActivity"
android:launchMode="singleTop"
android:theme="@style/ModuleATheme" />
... ...
</application>
Run Code Online (Sandbox Code Playgroud)
在模块 B 中也有一些活动。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oath.module_b">
<application
android:hardwareAccelerated="true"
android:largeHeap="true">
<activity
android:name="com.module_b.DetailsActivity"
android:launchMode="singleTop"
android:theme="@style/ModuleBTheme" />
... ...
</application>
Run Code Online (Sandbox Code Playgroud)
如果模块相互依赖,可以在模块的单独清单中包含 <application> 吗?
moduleA和moduleB都使用共享资源怎么办?
如果调用的应用程序AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
预期显示深色主题,如果不是,则显示浅色主题。
具有AlertDialog.Builder(this)
,并且希望应用一个主题,以便在MODE_NIGHT中它显示带有深色主题的对话框,否则,该对话框显示带有浅色主题的对话框,如下所示(但这android.R.style.Theme_Material_Dialog
将使对话框始终处于深色主题)
AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog)
Run Code Online (Sandbox Code Playgroud)
AlertDialog有一个主题吗?还是必须定义两个主题并检查模式,然后分别用该主题编码?
和
fun main(args: Array<String>) {
runBlocking {
withTimeout(1300L) {
repeat(1000) { i ->
println("I'm sleeping $i ...")
delay(500L)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它崩溃并出现异常:
I'm sleeping 0 ...
I'm sleeping 1 ...
I'm sleeping 2 ...
Exception in thread "main" kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 1300 ms
at kotlinx.coroutines.TimeoutKt.TimeoutCancellationException (Timeout.kt:128)
at kotlinx.coroutines.TimeoutCoroutine.run (Timeout.kt:94)
at kotlinx.coroutines.EventLoopImplBase$DelayedRunnableTask.run (EventLoop.kt:307)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent (EventLoop.kt:116)
at kotlinx.coroutines.DefaultExecutor.run (DefaultExecutor.kt:68)
at java.lang.Thread.run (Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
但块内launch
fun main(args: Array<String>) {
runBlocking {
launch {//<===
withTimeout(1300L) {
repeat(1000) { i -> …
Run Code Online (Sandbox Code Playgroud) android ×8
kotlin ×4
android-room ×1
animation ×1
dagger-2 ×1
exception ×1
filter ×1
hashmap ×1
listview ×1
module ×1
parcelable ×1
sql-delete ×1
themes ×1