我创建了Recycler View Grid.我希望实现分页.但我不明白它是怎么做的.我找到一个答案在这里输入链接描述
但它对我不起作用.mLayoutManager.findFirstVisibleItemPosition();我的LayOutManager中没有方法 .方法mRecyclerView.setOnScrollListener已弃用.如何在Recycler View Grid中实现分页?
我有Stream Stream<Integer> stream// 1,2,3,4,5,6,7,8,9
我需要int[3][3]从中创造stream
我该怎么做?
我试过了
int[][] ints = stream
.map(i -> new int[]{i})
.toArray(int[][]::new);
Run Code Online (Sandbox Code Playgroud)
但我得到: [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
但是我需要: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
编辑:我认为这不是dublicate 这是因为我需要int [3] [3]数组而不是String [] []
我试过这个例子
int[][] array =
IntStream.range(0, 3)
.mapToObj(x -> IntStream.range(0, 3).boxed()
.toArray(Integer[]::new))
.toArray(int[][]::new);
Run Code Online (Sandbox Code Playgroud)
我得到错误
Exception in thread "main" java.lang.ArrayStoreException: [Ljava.lang.Integer;
at java.util.stream.Nodes$FixedNodeBuilder.accept(Nodes.java:1222)
at java.util.stream.IntPipeline$4$1.accept(IntPipeline.java:250)
at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:545) …Run Code Online (Sandbox Code Playgroud) 我尝试使用RxAndroid
button.setOnClickListener(view -> restApiFactory.testService().getListTest(7)
.subscribeOn(Schedulers.io())
.subscribe(new Observer<List<Test>>() {
Run Code Online (Sandbox Code Playgroud)
我得到错误
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Run Code Online (Sandbox Code Playgroud)
我还没有 AndroidSchedulers.mainThread()
我在父pom中尝试像模块一样的弹簧启动,现在我得到了错误
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Failure to find org.springframework.boot:spring-boot-dependencies:pom:2.0.0.M6 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced @ line 30, column 19
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project mydomain.project:main-project:1.0-SNAPSHOT (D:\gitProjects\main-server\sources\pom.xml) has 1 error
[ERROR] Non-resolvable import POM: Failure to find org.springframework.boot:spring-boot-dependencies:pom:2.0.0.M6 in https://repo.maven.apache.org/maven2 …Run Code Online (Sandbox Code Playgroud) 我返回了 DAO 方法LiveData<List<Category>>:
LiveData<List<Category>> listLiveData = categoryDao.getAll();
Run Code Online (Sandbox Code Playgroud)
之后,我需要将此数据设置为我的适配器:
listLiveData.observe(this, categories -> {
if (categories == null || categories.isEmpty()) {
price.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.INVISIBLE);
} else {
categoryAdapter = new CategoryAdapter(categories);
categoryAdapter.setOnItemClickListener(new ClickHandler());
recyclerView.setAdapter(categoryAdapter);
}
});
Run Code Online (Sandbox Code Playgroud)
如果我在 DB 中没有数据,我会显示更新按钮(从服务器获取数据并插入到 DB)。如果我有数据,我会创建适配器并将数据设置为它。
之后,如果我将一些插入Category到数据库中,我会得到:
我认为这是非常糟糕的做法(创建一个新的适配器来更新每个项目),我可以通过某种方式:
更改我的适配器并添加方法 addData(List<Category> categories);
在 onCreateView 我创建适配器: categoryAdapter = new CategoryAdapter(new ArrayList());
然后当我在observe方法中获取数据时,我将其添加到适配器中:
adapter.addData(categories);
Run Code Online (Sandbox Code Playgroud)
并进入addData循环中的方法检查每个项目,如果不存在则添加到列表并通知数据。
改变方法
LiveData> listLiveData = categoryDao.getAll();
到
LiveData<Category> category = categoryDao.getLast();
Run Code Online (Sandbox Code Playgroud)
并将此项添加到observe方法中。但我有两个问题: 1 - 如何首先添加所有数据?我必须实现 2 …
我有实体:
@Entity(tableName = "products")
public class Product{
@PrimaryKey(autoGenerate = true)
private Long id;
@ColumnInfo(name = "amount")
private BigDecimal amount;
Run Code Online (Sandbox Code Playgroud)
我需要将其存储在Room DB中。我无法存储BigDecimal并创建转换器:
public static class Converters {
@TypeConverter
public BigDecimal fromString(String value) {
return value == null ? null : new BigDecimal(value);
}
@TypeConverter
public Double amountToString(BigDecimal bigDecimal) {
if (bigDecimal == null) {
return null;
} else {
return bigDecimal.doubleValue();
}
}
}
Run Code Online (Sandbox Code Playgroud)
并添加到列:
@TypeConverters(Converters.class)
@ColumnInfo(name = "amount")
private BigDecimal amount;
Run Code Online (Sandbox Code Playgroud)
现在,我将货币存储在双列中。我想要求和summarycurrency的方法:
@Query("SELECT SUM(amount) FROM products")
LiveData<Double> totalSum(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试实施数据库迁移Flyway 4.2.0 + Oracle 11g
我有这个空架构:
当我尝试迁移时,Flyway 说:
原因::
org.flywaydb.core.api.FlywayException发现非空模式“PASHA”,没有元数据表!使用baseline()或设置baselineOnMigrate为true初始化元数据表。
这是配置:
@Bean(initMethod = "migrate")
Flyway flyway() {
Flyway flyway = new Flyway();
flyway.setBaselineOnMigrate(false);
flyway.setSchemas("PASHA");
flyway.setLocations("classpath:db/migration/oracle");
flyway.setDataSource("jdbc:oracle:thin:@host:1521:test", "login", "password");
return flyway;
}
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此消息?我的基地是空的。
我有这样的课程:
public enum Type {
ONE, TWO
}
@Data
public class Car {
private String name;
private int year;
private Type type;
}
Run Code Online (Sandbox Code Playgroud)
我有新对象:
Car car = new Car();
Run Code Online (Sandbox Code Playgroud)
我有这个数据:
Map<String, String> data....
name - BMW
year - 2018
type - TWO
Run Code Online (Sandbox Code Playgroud)
键和值 - 字符串
我需要将此值设置为对象(除了反射,我看不出有什么办法)
Field year = car.getClass().getDeclaredField("year");
year.setAccessible(true);
year.set(car, data.get("year"));//2018 as string
Run Code Online (Sandbox Code Playgroud)
我得到异常(不同,我不知道):
Caused by: java.lang.IllegalArgumentException: Can not set int field com.example.mapper.Car.year to java.lang.String
Run Code Online (Sandbox Code Playgroud)
因此,问题是 - 如何正确地将值转换为要在字段中设置的所需类型?
这是一个简单的例子,因为真正的任务解释起来很长。简而言之 - 我得到一个值列表(它们始终是一个字符串)以及它们更改的字段名称(也是一个字符串),并且必须使用新值更新对象的字段
我有一个使用Gradle构建的Spring Boot项目。当我项目时,我有这些外部库,标记为. 我可以在我的课堂上使用它:clean/buildlibrary rootimport org.gradle.api.tasks.*
现在我创建了一个新项目,但这些库不存在。我不明白如何配置它。我想在新项目中使用import org.gradle.api.tasks.*,但我做不到。
我在实体中有字段:
@Column(name = "BILL_DATE")
private LocalDate billDate;
Run Code Online (Sandbox Code Playgroud)
我的系统与oracle和 一起工作posthresql。在 posgresql 中,此列具有类型,timestamp但在 oracle - 中date。当我尝试启动服务器时postgeSQL出现错误:
wrong column type encountered in column [bill_date] in table [charges]; found [timestamp (Types#TIMESTAMP)], but expecting [date (Types#DATE)]
Run Code Online (Sandbox Code Playgroud)
如果我添加注释,@Temporal(TemporalType.DATE)我会收到另一个错误:
Caused by: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property
Run Code Online (Sandbox Code Playgroud)
但我不想使用java.util.Date和java.util.Calendar。如何解决这个问题呢?
java ×6
android ×4
spring-boot ×2
android-room ×1
arrays ×1
build.gradle ×1
flyway ×1
gradle ×1
gradlew ×1
hibernate ×1
java-stream ×1
localdate ×1
maven ×1
oracle11g ×1
reflection ×1
retrofit2 ×1
rx-android ×1
timestamp ×1