小编aba*_*lta的帖子

新的Flutter项目向导未在Android Studio 3.0.1上显示

我按照官方文档安装了Flutter,并在Android Studio上安装了Flutter和Dart插件.

但是,我在Android Studio 3.0.1上看不到File> New Flutter Project向导

我跑"颤动的医生"命令.见下面的输出.

Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel beta, v0.1.5, on Mac OS X 10.13.3 17D102, locale en-TR)
[?] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[?] iOS toolchain - develop for iOS devices (Xcode 9.2)
[?] Android Studio (version 3.0)
[?] IntelliJ IDEA Community Edition (version 2017.3.3)
[!] Connected devices
    ! No devices available

! Doctor found issues in 1 category.
Run Code Online (Sandbox Code Playgroud)

dart flutter android-studio-3.0

19
推荐指数
10
解决办法
8632
查看次数

具有不同导航图的相同片段(由 hiltNavGraphViewModels 提供)

我的应用程序遵循单一活动模式。我的 MainActivity 有一个包含 4 个片段的底部导航。

主导航图

nav_homenav_video具有相同的片段,因此我希望 HomeViewModel 和 VideoViewModel 将其状态保留在这些图中。正如你在下面看到的。

nav_home.xml

导航主页图

nav_video.xml

导航视频图

在我的片段中,我使用hiltNavGraphViewModels扩展来保持视图模型状态。

@AndroidEntryPoint
class CourseDetailFragment : Fragment(R.layout.fragment_course_detail),
    LoadingDelegate by LoadingDelegateImpl(), NavigationDelegate by NavigationDelegateImpl() {

    private val binding by viewBinding(FragmentCourseDetailBinding::bind)
    private val viewModel: CourseDetailViewModel by viewModels()
    private val categoryViewModel: CategoryViewModel by hiltNavGraphViewModels(R.id.nav_video)
    private val homeViewModel: HomeViewModel by hiltNavGraphViewModels(R.id.nav_home)
Run Code Online (Sandbox Code Playgroud)

如果我从家里到达这个片段,categoryViewModel 会抛出异常,并显示:

java.lang.IllegalArgumentException: NavController 的返回堆栈上没有 ID 为 2131362218 的目标。当前目的地是 Destination(com.example.app:id/courseDetailFragment) label=CourseDetailFragment class=com.example.app.ui.course.CourseDetailFragment

日志异常

另一方面,如果我从视频中到达这个片段,homeViewModel 会抛出相同的异常。

任何帮助将受到热烈欢迎。谢谢。

navigation android android-fragments android-jetpack-navigation dagger-hilt

7
推荐指数
1
解决办法
560
查看次数

可分配更改Android上的资源ID

我有Product类,它实现了Parcelable.这个类有一些图像,这些图像路径保存在strings.xml中.我有产品对象到另一个活动,但图像资源更改.所以,我得到ResourcesNotFoundExceptions.

这是我的strings.xml

 <string-array name="prod_images">
    <item>@drawable/sample_product_one</item>
    <item>@drawable/sample_product_two</item>
    <item>@drawable/sample_product_three</item>
    <item>@drawable/sample_product_four</item>
</string-array>
Run Code Online (Sandbox Code Playgroud)

我的Product.java类.

public class Product implements Parcelable {

private int productId;
private int productImage;
private String productTitle;
private String productPrice;

public Product() {
}

public int getProductImage() {
    return productImage;
}

public void setProductImage(int productImage) {
    this.productImage = productImage;
}

public String getProductTitle() {
    return productTitle;
}

public void setProductTitle(String productTitle) {
    this.productTitle = productTitle;
}

public String getProductPrice() {
    return productPrice;
}

public void setProductPrice(String productPrice) {
    this.productPrice = productPrice;
} …
Run Code Online (Sandbox Code Playgroud)

android parcelable android-activity android-resources

0
推荐指数
1
解决办法
171
查看次数