我在Recycler视图android中发现了类似问题的Facebook原生广告,但在与自定义广告的集成方面遇到了一些问题.
对于我试图描述的第一个NativeAdsManager:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
manager = new NativeAdsManager(getActivity(), "892769720837476_892772047503910", 5);
manager.setListener(this);
manager.loadAds();
nativeAd = new NativeAd(getActivity(), "892769720837476_892772047503910");
nativeAd.setAdListener(this);
nativeAd.loadAd();
...
}
Run Code Online (Sandbox Code Playgroud)
然后我Native ad作为参数包含在RecyclerAdapter构造函数中:
adapter = new RecyclerAdapter(foodDataList, getActivity(), nativeAd);
Run Code Online (Sandbox Code Playgroud)
在这个Class我也实现AdListener和NativeAdsManager.Listener方法:
@Override
public void onError(Ad ad, AdError adError) {
}
@Override
public void onAdLoaded(Ad ad) {
}
@Override
public void onAdClicked(Ad ad) {
}
@Override
public …Run Code Online (Sandbox Code Playgroud) java android facebook-audience-network recycler-adapter android-recyclerview
通知 Android 我需要触摸屏幕左侧才能拉出抽屉的正确方法是什么?现在在 Q beta 3 上它会返回而不是拉出抽屉。我寻找文档但找不到任何文档。
我想在我的应用程序中使用TextInputEditText和TextInputLayout,但它不适用于Theme.AppCompat.Light.NoActionBar. 但是如果我将它设置为Theme.MaterialComponents.Light.NoActionBar,它将毫无问题地工作,但这会破坏我在应用程序中的所有样式。
XML 中的用法:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/reg_edit_text_style"
app:errorEnabled="true"
android:hint="@string/name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nameEt"
android:layout_width="match_parent"
android:nextFocusDown="@id/lastNameEt"
android:inputType="text"
style="@style/reg_edit_text_inner_style"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
在build.gradle:
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'androidx.appcompat:appcompat:1.0.2'
Run Code Online (Sandbox Code Playgroud)
错误:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
Run Code Online (Sandbox Code Playgroud) 我正在开始一个新项目,我将与10个开发人员组成一个团队。我正在为我们的Android应用设置基础结构。在与团队合作时,我希望每个人都遵循相同的结构,即为ViewModel每个人创建fragment并使用数据绑定。我如何使其严格,以使开发人员在未ViewModel为其片段创建代码时出错?
所以我创建了以下内容BaseFragment:
abstract class BaseFragment<out VM : BaseViewModel, DB : ViewDataBinding> : Fragment() {
open lateinit var binding: DB
private fun init(inflater: LayoutInflater, container: ViewGroup?) {
binding = DataBindingUtil.inflate(inflater, getLayoutRes(), container, false)
}
@LayoutRes
abstract fun getLayoutRes(): Int
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
init(inflater, container)
super.onCreateView(inflater, container, savedInstanceState)
return binding.root
}
open fun refresh() {}
}
Run Code Online (Sandbox Code Playgroud)
我该如何进一步改善?
android android-fragments kotlin android-architecture-components
我有在浏览器中打开 URL 的简单代码:
startActivity(Intent(
Intent.ACTION_VIEW, Uri.parse(resources.getString(R.string.application_url))
))
Run Code Online (Sandbox Code Playgroud)
如何将其转换为导航组件项?
我是否需要为此构建自定义导航器,或者导航组件为这种情况内置了一些东西?
我的应用程序中有一些页面,每个页面都是一个带有自己 ViewModel 的片段,并且所有页面都在 FrameLayout 中相互交换(我有特殊的 BottomNavigationView 来处理它们的交换)。
所以我想用 ViewPager2 替换 FrameLayout,但在这种情况下,我必须向 RecyclerView.Adapter 提供视图而不是片段,我的解决方案是将片段包装到一些视图中,例如 LinearLayout。
所以我的问题是:我认为这是最简单的解决方案吗?有没有更好的解决方案?
我尝试使用 a 将我的数据从 传递adapter给我的另一个activity,putExtra但是当我单击列表中的一个项目移动到我的第二个时activity,没有检索到任何数据,也没有显示我输入的默认文本。另一种方法呢?或者我想念它什么?这是我的代码:
我的
onBindViewHolder:
override fun onBindViewHolder(holder: AlbumsListViewHolder, position: Int) {
val AlbumsData = albumsData!![position]
holder.albumsName.text = AlbumsData.title
Glide.with(holder.itemView)
.load(AlbumsData.cover)
.transition(DrawableTransitionOptions.withCrossFade())
.into(holder.coverImage)
holder.itemView.setOnClickListener {
val intent = Intent(holder.itemView.context, TracksActivity::class.java)
//listener?.onClick(AlbumsData)
intent.putExtra("dd", "ff")
holder.itemView.context.startActivity(intent)
}
}
Run Code Online (Sandbox Code Playgroud)
我的第二个
Activity:
class TracksActivity: AppCompatActivity(), TracksView {
private var albumsAdapter: AlbumsAdapter? = null
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
setContentView(R.layout.activity_tracks)
//albumsAdapter = findViewById(R.id.trackslist_recycleview)
val msg = intent.getStringExtra("dd")
Log.d("dd", "${msg}")
} …Run Code Online (Sandbox Code Playgroud) android android-intent android-activity kotlin android-recyclerview
我有下面的模型,其中包括date和time领域
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.time.LocalDate
import java.time.LocalTime
@Entity
data class Assignment(
@PrimaryKey(autoGenerate = true) val tid: Int,
// @PrimaryKey val uid: Int,
@ColumnInfo(name = "id") val id: Int,
@ColumnInfo(name = "task") val task: String?,
@ColumnInfo(name = "address") val address: String?,
@ColumnInfo(name = "datePicker") val datePicker: LocalDate?,
@ColumnInfo(name = "timePicker") val timePicker: LocalTime?,
@ColumnInfo(name = "status") val status: String?
)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
无法弄清楚如何将此字段保存到数据库中。您可以考虑为其添加类型转换器。
所以,我写了下面的转换器:
import java.sql.Date
import java.time.LocalDate
import javax.persistence.AttributeConverter
import javax.persistence.Converter
import java.time.ZoneId.systemDefault
@Converter(autoApply = …Run Code Online (Sandbox Code Playgroud) 我已经在 Android 中使用导航组件实现了导航抽屉。我有 5 个片段,HomeFragment当我点击后退按钮时,我想回到我的片段。目前,它们停留在 BackStack 上,不会转到我想要的片段,而是转到第一个片段。这是我的nav_graph:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/setupFragment"
android:id="@+id/treasure_nav"
android:label="Pick a country">
<fragment android:id="@+id/homeFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.home.HomeFragment"
android:label="Home"
tools:layout="@layout/fragment_home">
<action android:id="@+id/action_home_fragment_to_namesFragment2"
app:popUpTo="@id/homeFragment"
app:destination="@id/namesFragment"/>
<action android:id="@+id/action_home_fragment_to_quranFragment"
app:popUpTo="@id/homeFragment"
app:destination="@id/quranFragment"/>
<action android:id="@+id/action_homeFragment_to_tasbeehFragment"
app:popUpTo="@id/homeFragment"
app:destination="@id/tasbeehFragment"/>
<action android:id="@+id/action_homeFragment_to_galleryFragment"
app:popUpTo="@id/homeFragment"
app:destination="@id/galleryFragment"/>
<action android:id="@+id/action_homeFragment_to_newsFragment"
app:popUpTo="@id/homeFragment"
app:destination="@id/newsFragment"/>
<action android:id="@+id/action_homeFragment_to_settingsFragment"
app:popUpTo="@id/homeFragment"
app:destination="@id/settingsFragment"/>
</fragment>
<fragment
android:id="@+id/namesFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.names.NamesFragment"
android:label="Names of Allah"
tools:layout="@layout/fragment_names"/>
<fragment
android:id="@+id/quranFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.quran.QuranFragment"
android:label="Quran"
tools:layout="@layout/fragment_quran"/>
<fragment android:id="@+id/tasbeehFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.tasbeeh.TasbeehFragment"
android:label="Tasbeeh"
tools:layout="@layout/fragment_tasbeeh"/>
<fragment android:id="@+id/galleryFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.gallery.GalleryFragment"
android:label="Gallery"
tools:layout="@layout/fragment_gallery"/>
<fragment android:id="@+id/newsFragment"
android:name="com.stavro_xhardha.pockettreasure.ui.news.NewsFragment"
android:label="News"
tools:layout="@layout/fragment_news"/> …Run Code Online (Sandbox Code Playgroud) android android-fragments navigation-drawer android-architecture-navigation
我想将按钮单击绑定到视图模型内的挂起函数。
这是我的代码:
RegistrationActivityViewModel.kt
suspend fun register() {
if (validateFields()) {
val result = SourceplusplusApiService.invoke().registerUser(username.value!!, email.value!!, password.value!!).await()
isRegistrationCompleted.value = getResultValue(result)
}
}
Run Code Online (Sandbox Code Playgroud)
活动注册.xml
<Button
android:text="Register"
android:onClick="@{()->viewmodel.register()}"
android:textSize="16sp" />
Run Code Online (Sandbox Code Playgroud)
我收到一个数据绑定错误,提示ActivityRegistrationBindingImpl未生成。经过大量搜索后,我意识到当我删除suspend关键字并注释里面的代码时,它工作正常,但它必须是一个挂起的函数。
有谁知道如何修理它?
android ×10
kotlin ×5
android-architecture-navigation ×3
android-architecture-components ×1
android-room ×1
androidx ×1
fragment ×1
java ×1