小编fai*_*gir的帖子

使用导航主机在底部导航中停止片段刷新

这个问题已经被问过几次了,但我们现在是 2020 年,有没有人找到一个很好的可用解决方案呢?

我希望能够使用底部导航控件进行导航,而无需在每次选择片段时刷新它们。这是我目前所拥有的:

导航/main.xml:

<?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"
    android:id="@+id/main"
    app:startDestination="@id/home">

    <fragment
        android:id="@+id/home"
        android:name="com.org.ftech.fragment.HomeFragment"
        android:label="@string/app_name"
        tools:layout="@layout/fragment_home" />
    <fragment
        android:id="@+id/news"
        android:name="com.org.ftech.fragment.NewsFragment"
        android:label="News"
        tools:layout="@layout/fragment_news"/>
    <fragment
        android:id="@+id/markets"
        android:name="com.org.ftech.fragment.MarketsFragment"
        android:label="Markets"
        tools:layout="@layout/fragment_markets"/>
    <fragment
        android:id="@+id/explore"
        android:name="com.org.ftech.ExploreFragment"
        android:label="Explore"
        tools:layout="@layout/fragment_explore"/>
</navigation>
Run Code Online (Sandbox Code Playgroud)

活动邮件.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<androidx.drawerlayout.widget.DrawerLayout
    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"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/main" />

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:itemIconTint="@color/nav"
            app:itemTextColor="@color/nav"
            app:layout_constraintBottom_toBottomOf="parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments kotlin

19
推荐指数
4
解决办法
1万
查看次数

比较可空的日期时间对象

我有两个可以为空的日期时间对象,我想比较两者.最好的方法是什么?

我已经尝试过了:

DateTime.Compare(birthDate, hireDate);
Run Code Online (Sandbox Code Playgroud)

这是一个错误,也许是期待类型的日期,System.DateTime我有Nullable日期时间.

我也尝试过:

birthDate > hiredate...
Run Code Online (Sandbox Code Playgroud)

但结果不如预期......任何建议?

c# datetime compare nullable

13
推荐指数
2
解决办法
2万
查看次数

对象数组的自定义排序顺序

我知道我们可以定义json对象数组的自定义排序函数.但是,如果订单既不是,那怎么办desc nor asc?例如,假设我的数组看起来像:

[ {
    name: 'u'
  },
  {
    name: 'n'
  },
  {
    name: 'a'
  },
  { 
    name: 'n',
  } 
]
Run Code Online (Sandbox Code Playgroud)

输出应如下所示:

[ {
    name: 'n'
  },
  {
    name: 'n'
  },
  {
    name: 'a'
  },
  { 
    name: 'u',
  } 
]
Run Code Online (Sandbox Code Playgroud)

所有以名称开头的名称首先n排序,然后排序.我尝试了以下自定义排序功能:

_sortByName(a, b){
        if (a.name === 'n'){
            return 1;
        } else if(b.name === 'n'){
            return 1;
        } else if(a.name < b.name){
            return 1;
        } else if(a.name > b.name){
            return -1;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是返回对象的顺序是错误的.这里出了什么问题?

javascript arrays sorting

8
推荐指数
1
解决办法
3509
查看次数

spring boot starter graphql 不工作

我最近开始使用graphql它并发现它非常有趣。由于大多数我的rest应用程序都在java,我决定做一个快速安装使用所提供的春天开机启动的项目graphql-java团队。它带有graph-iqlautoconf spring 设置,可以更轻松地查询/graphql端点。

在 IDEA 中的项目设置上花了几个小时后,我能够运行graphql-sample-app。但我认为我的 servlet 仍未启用,只有graphiql端点正在运行,因为默认查询返回404.

这是application.yml

spring:
      application:
               name: graphql-todo-app
server:
      port: 9000

graphql:
      spring-graphql-common:
               clientMutationIdName: clientMutationId
               injectClientMutationId: true
               allowEmptyClientMutationId: false
               mutationInputArgumentName: input
               outputObjectNamePrefix: Payload
               inputObjectNamePrefix: Input
               schemaMutationObjectName: Mutation
      servlet:
             mapping: /graphql
             enabled: true
             corsEnabled: true

graphiql:
    mapping: /graphiql
    enabled: true
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradle文件的样子:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
        maven { …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot graphql graphql-java

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

setOnItemClickListener() not working on gridView

I know this is already been asked, but somehow the solutions do not work for me.

I have a gridView which is inflated by a relativeLayout. The adapter sets perfectly, When I add a clickListener to one of the childs of relativeLayout they also work fine. But not the itemClickListener on the gridview.

Here is what I have tried:

Gridview:

<GridView
            android:id="@+id/gridView"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:clipToPadding="true"
            android:columnWidth="170dp"
            android:fitsSystemWindows="true"
            android:focusable="true"
            android:numColumns="auto_fit"
            android:stretchMode="columnWidth" >
</GridView>
Run Code Online (Sandbox Code Playgroud)

Relativelayout added in gridview: …

android gridview android-layout android-gridview

6
推荐指数
2
解决办法
6775
查看次数

使用动态规划抄书

我正在实施用于抄书问题的动态编程解决方案。解决方案的想法来自herehere

问题陈述:

在书籍印刷发明之前,复印一本书非常困难。所有的内容都必须由所谓的抄写员手工重写。抄写员得到了一本书,几个月后他完成了副本。最著名的抄写员之一生活在 15 世纪,他的名字是 Xaverius Endricus Remius Ontius Xendrianus(施乐)。总之,工作很烦很无聊。而加快速度的唯一方法就是雇佣更多的抄写员。

曾几何时,有一个剧团想演著名的古董悲剧。这些剧本的剧本被分成了很多书,演员当然需要更多的副本。因此,他们聘请了许多抄写员来复印这些书。假设您有 m 本书(编号为 1、2、....、m),它们的页数可能不同(p_1、p_2、...、p_m),并且您想为每本书制作一份副本。你的任务是将这些书分给 k 个抄写员,k <= m。每本书只能分配给一个抄写员,并且每个抄写员都必须获得连续的书籍序列。这意味着,存在一个递增的数字序列 0 = b_0 < b_1 < b_2, ... < b_{k-1} <= b_k = m$ 使得第 i 个抄写员得到一个数字介于 bi- 1+1 和双。复印所有书籍所需的时间由分配最多工作的抄写员决定。因此,我们的目标是尽量减少分配给单个抄写员的最大页面数。您的任务是找到最佳分配。

我能够获得迭代描述的问题的最佳解决方案,但无法使用它来找到问题所需的解决方案,即:

Sample input:
2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100

Sample Output
100 200 300 400 500 / 600 700 / 800 900
100 / 100 …
Run Code Online (Sandbox Code Playgroud)

java algorithm recurrence dynamic-programming

6
推荐指数
1
解决办法
1741
查看次数

webpack 未加载 svgs

我有以下内容app structure

/webapp
  /lib
    /assets
      ic_add_black_24px.svg
      ic_clear_black_24px.svg
      ..
      ..
Run Code Online (Sandbox Code Playgroud)

这是我的webpack.config.js

var path = require('path'),
    webpack = require("webpack"),
    libPath = path.join(__dirname, 'lib'),
    wwwPath = path.join(__dirname, 'www'),
    pkg = require(path.join(__dirname,'package.json')),
    HtmlWebpackPlugin = require('html-webpack-plugin');


var config = {
    entry: path.join(libPath, 'index.js'),
    output: {
        path: path.join(wwwPath),
        filename: 'bundle-[hash:6].js'
    },
    module: {
        loaders: [{
            test: /\.html$/,
            loader: 'file?name=templates/[name]-[hash:6].html'
        }, {
            test: /\.(png|jpg|svg)$/,
            loader: 'file-loader?name=assets/[name].[ext]' // inline base64 URLs for <=10kb images, direct URLs for the rest
        }, {
            test: /\.css$/,
            loader: …
Run Code Online (Sandbox Code Playgroud)

javascript svg angularjs webpack

5
推荐指数
1
解决办法
6550
查看次数

覆盖垫树的填充

我在这里使用这个例子来构建一个mat-tree使用 flat 的datasource. 现在我想重写默认padding-left40px为所有的孩子之后。这就是我的做法:

mat-tree-node:not(:first-child) {
    padding-left: 16px;
}
Run Code Online (Sandbox Code Playgroud)

这有效,但仅16px在树节点的第 2 级设置填充。当我继续扩展它们时,其余的嵌套子级不会累积 16px。是否可以覆盖matTreeNodePadding指令?

css angular-material2 angular

5
推荐指数
1
解决办法
4264
查看次数

使用三元运算符将null分配给十进制

我正在使用转换为decimala byte array,使其包含null以字节存储的任一或任何其他数字.这里的问题是,当我尝试将转换nullNullable decimal,将其转换它zero.我希望它继续null......

Convert.ToDecimal(obj.sal== null ? null : System.Text.Encoding.ASCII.GetString(obj.sal))
Run Code Online (Sandbox Code Playgroud)

c#

4
推荐指数
1
解决办法
4323
查看次数

将函数作为参数传递给 Action

我试图通过一个方法作为一个动作,但似乎不是每说一次。

这就是我的做法:

public class RequestHandler<T> where T : struct
{
    public enum EmployeeRequests { BasicDetails, DependentsAndEmergencyContacts , MedicalHistory }

    protected Dictionary<T, Action> handlers = new Dictionary<T, Action>();

    protected EmployeeManagement empMgmnt = new EmployeeManagement();

    public void InitializeHandler(int employeeID)
    {

        this.AddHandler(EmployeeRequests.BasicDetails, () => empMgmnt.GetEmployeeBasicDetails(0));
    }

    public void AddHandler(T caseValue, Action action)
    {
        handlers.Add(caseValue, action);
    }

    public void RemoveHandler(T caseValue)
    {
        handlers.Remove(caseValue);
    }

    public void ExecuteHandler(T actualValue)
    {
        ExecuteHandler(actualValue, Enumerable.Empty<T>());
    }

    public void ExecuteHandler(T actualValue, IEnumerable<T> ensureExistence)
    {
        foreach(var val in ensureExistence)
            if …
Run Code Online (Sandbox Code Playgroud)

c# delegates action

4
推荐指数
1
解决办法
7555
查看次数