我想使用 Hilt 在运行时为 ViewModel 提供一些依赖项。我已遵循 d.android.com this指导的解决方案。
@HiltViewModel
public class ViewViewModel extends ViewModel {
...
@AssistedFactory
public interface ViewViewModelFactory {
ViewViewModel create(@Assisted int version);
}
@AssistedInject
public ViewViewModel(ProfileRepository repository, @Assisted int version) {
mProfileRepository = repository;
}
}
@AndroidEntryPoint
public class CarFragment extends Fragment {
@Inject
ViewViewModel.ViewViewModelFactory mViewViewModelFactory;
...
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
ViewViewModel viewModel = mViewViewModelFactory.create(21);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,仍然出现构建错误ViewModel constructor should be annotated with @Inject instead of @AssistedInject.
我使用的是 hilt …
我对 UMP SDK 的实现有很多困惑。除了谷歌之外,我没有找到太多信息或完整教程。我正在关注这个和这个,但无法理解以下问题:
MobileAds.initialize()
征得同意后需要打电话吗?如果是这样,那么它应该在哪里调用?获得同意后可能会调用:
public void onConsentFormLoadSuccess(ConsentForm consentForm) {
if(consentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.OBTAINED) {
}
}
Run Code Online (Sandbox Code Playgroud)
我如何检查用户是否来自欧洲经济区?我想根据用户位置请求同意或初始化移动广告。在Consent SDK 中,有一个 method isRequestLocationInEeaOrUnknown()
,但此 SDK 已弃用。我在 UMP SDK 中没有找到类似的东西。一种方法可能是始终requestConsentInfoUpdate
调用isConsentFormAvailable
inside onConsentInfoUpdateSuccess
。如果用户不是来自 EEA,则此方法返回 false。
我总是得到同意类型consentInformation.getConsentType()
0 或未知。我尝试过不同的组合,但总是 0。
是否需要将同意信息转发给 AdMob SDK 或 SDK 会处理。
关于调解,我需要同意信息,但不知道如何获取。从文档:The UMP SDK writes consent status information to local storage
在 AdMob -> 欧盟用户同意中,我的中介合作伙伴之一未包含在Commonly used set of ad technology providers
. 如果我使用Custom …
android admob mobile-ad-mediation gdprconsentform user-messaging-platform
我正在使用数据库检查器来查询数据库。但是,我想知道优化查询性能的执行时间。有谁知道获取查询的执行时间吗?
如何使用不属于任何形式的字段的形式将参数从jsp传递给servlet而不使用session.i认为代码可能看起来像下面的示例,但不适用于me.plz帮助我.
在index.jsp中: -
<form method="Post" action="servlet">
<input type="text" name="username">
<input type="password" name="password">
<%
int z=1;
request.setAttribute("product_no", z);%>
<input type='submit' />
</form>
Run Code Online (Sandbox Code Playgroud)
在servlet.java:-
int x=Integer.parseInt(request.getAttribute("product_no").toString());
Run Code Online (Sandbox Code Playgroud) 我有片段 A、B、C 和 X,它们的导航如下。
A --> X
B --> X
C --> X
Run Code Online (Sandbox Code Playgroud)
我怎么知道X中最后一个或上一个目的地的信息?
可以通过以下方式找到当前的目的地 ID
Navigation.findNavController(v).getCurrentDestination().getId()
Run Code Online (Sandbox Code Playgroud)
我也尝试使用,getBackStackEntry(int destinationId)
但它只返回目标 ID 的最顶层 NavBackStackEntry。换句话说,当前目的地。
也getActivity().getSupportFragmentManager().getBackStackEntryCount();
返回0。
可能的解决方案是:
是否有可能获得当前目的地?
我正在尝试使用 Java 实现 CameraX。我不明白他们为什么用这样的说法。
new ImageCaptureConfig.Builder().build();
new PreviewConfig.Builder().build();
Run Code Online (Sandbox Code Playgroud)
每当我尝试实现时,它都会显示编译错误,并且 Builder 类仍保持红色。
编译错误:
reference to 'Builder' is ambigious, both 'androidx.camera.core.impl.UseCaseConfig.Builder' and 'androidx.camera.core.impl.ImageOutputConfig.Builder'
Run Code Online (Sandbox Code Playgroud)
进口:
import androidx.camera.core.impl.ImageCaptureConfig;
Run Code Online (Sandbox Code Playgroud)
我在 ImageCaptureConfig.java 文件中没有找到任何内部类“Builder”。然而,
Builder 用于接口 UseCaseConfig.java 和 ImageOutputConfig.java,后者已由 ImageCaptureConfig.java 实现。我这里如何实现Builder并避免二义性错误?
我已使用开发人员网站上的最新依赖项和说明。我没有明白我错在哪里。
我在我的项目中使用材料日历视图。我可以使用 setSelectedDate() 方法更改日期的选择。我有一个按钮作为“今天的选择”。我的目的是通过点击这个按钮将视图移动到当前日期。有方法 goToNext() 和 goToPrevious() 只改变一个月。但如果是两个月或更长时间向前或向后,那么我应该如何将视图更改为选定日期或当前日期。我尝试使用 invalidate() 但没有任何反应。
我在第一个AutoCompleteTextView上收到警告(在布局文件中找到意外的文字:""").我认为相对布局存在问题,因为当我删除文本视图时,我得到相同的错误,但不知道发生了什么. .. :(我已经尝试过但很失望.请帮我解决这个问题....这是我的xml代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
>
<TextView
android:id="@+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/from"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#588810"/>
<AutoCompleteTextView
android:id="@+id/from_station"
android:layout_below="@id/from"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="@string/hint_from"
android:ems="10" >
</AutoCompleteTextView>
<TextView
android:id="@+id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_below="@id/from_station"
android:text="@string/to"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#588810"/>
<AutoCompleteTextView
android:id="@+id/to_station"
android:layout_below="@id/to"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="@string/hint_to"
android:ems="0"
android:textColor="#588810">
</AutoCompleteTextView>
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) android ×7
java ×3
admob ×1
calendarview ×1
dagger-hilt ×1
jsp ×1
navigation ×1
servlets ×1
viewmodel ×1
xml ×1