小编use*_*311的帖子

Duration.ofDays生成UnsupportedTemporalTypeException

我正在尝试学习新的Date&Time API.我的代码工作除了最后一行:

LocalDate current=LocalDate.now();
System.out.println(current);

LocalDate personaldate=LocalDate.of(2011,Month.AUGUST, 15);
System.out.println(personaldate);

LocalDate afterten=current.plus(Period.ofDays(10));
System.out.println(afterten);

// error occurs here        
System.out.println(afterten.plus(Duration.ofDays(3)));
Run Code Online (Sandbox Code Playgroud)

当我尝试以天为单位添加持续时间时,会生成错误.谁能帮我理解为什么?

错误:

Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds                                                                                             
        at java.time.LocalDate.plus(LocalDate.java:1241)                                                                                                                                              
        at java.time.LocalDate.plus(LocalDate.java:137)                                                                                                                                               
        at java.time.Duration.addTo(Duration.java:1070)                                                                                                                                               
        at java.time.LocalDate.plus(LocalDate.java:1143)                                                                                                                                              
        at TestClass.main(TestClass.java:15)    
Run Code Online (Sandbox Code Playgroud)

java duration java-time

12
推荐指数
3
解决办法
1万
查看次数

Android Studio 上显示的透明模拟器

我正在尝试在 Android Studio 3.0.1 上运行我的第一个程序。然而,当我启动模拟器时,它变得透明,上面什么也没有显示。

在此输入图像描述

android android-emulator

10
推荐指数
2
解决办法
5519
查看次数

动态地向我的活动布局添加多个片段

我有一个没有子视图的linearlayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想根据需要动态添加一个片段或两个片段.我知道添加一个片段,但我怎么能动态地向它添加两个片段.我有两个片段,在每个片段中我写下以下oncreateview

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        //return super.onCreateView(inflater, container, savedInstanceState);
        View v=inflater.inflate(R.layout.frag1, container, false);
        v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

        return v; 
    }
Run Code Online (Sandbox Code Playgroud)

我试图使用以下代码添加,但第二个片段来自第一个.

FragmentTransaction ft=fm.beginTransaction();
        frag1 f=new frag1();
        frag2 ff=new frag2();


        ft.add(android.R.id.content, f);
        ft.add(android.R.id.content, ff);

        ft.commit();
Run Code Online (Sandbox Code Playgroud)

请更新如何做到这一点.谢谢

android

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

如何使用imeactionId的值

我试图把我自己的价值imeActionId,然后比较相同的actionIdonEditorAction.但是actionId在方法中反复返回0.

<EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="text|textUri"
        android:imeOptions="actionGo"
        android:imeActionId="666" 
        android:imeActionLabel="google"/>
Run Code Online (Sandbox Code Playgroud)

以下是我的onEditorAction:

et.setOnEditorActionListener(new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        // TODO Auto-generated method stub
        Log.v("myid iss", "" + actionId);

        if(actionId == 666)
        {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse("http://" + v.getText().toString()));

            imm.hideSoftInputFromInputMethod(v.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
            startActivity(i);
        }
        return false;
    }
});
Run Code Online (Sandbox Code Playgroud)

actionId来了,不论在XML值的每一次为0.如何使用我的定义imeActionId进行比较actionId.

android

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

CardView在RecyclerView中选择了背景颜色

我正在尝试使用CardViews编写RecyclerView并使用CAB尝试在选择时删除多张卡.如何为所选卡片提供背景颜色.我正在尝试使用statelistdrawable如下:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_activated="true" android:drawable="@color/primary_dark" />

    <item android:drawable="@android:color/transparent" />

</selector>
Run Code Online (Sandbox Code Playgroud)

并将其应用于CardView布局:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
android:background="@drawable/statelist_item_background"
        card_view:cardCornerRadius="10dp"
    card_view:cardElevation="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"


    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"

        >

        <ImageView
            android:id="@+id/imageView"
            android:tag="image_tag"
            android:layout_width="72dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:src="@drawable/one"/>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:layout_weight="2"
            android:orientation="vertical"
            >

            <TextView
                android:id="@+id/textViewName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Large Text"
                android:textAppearance="?android:attr/textAppearanceLarge"/>

            <TextView
                android:id="@+id/textViewEmail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"

                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"/>

        </LinearLayout>
    </LinearLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

下面是我的适配器的代码

public class modeladapter extends RecyclerView.Adapter<modeladapter.myholder> {

    ArrayList<MyModel> arraylist;
SparseBooleanArray selecteditems;
    public modeladapter(ArrayList<MyModel> …
Run Code Online (Sandbox Code Playgroud)

android

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

CollapsingToolbarLayout的不同scrollFlags之间的区别

我正在尝试学习CollapsingToolbarLayout,它具有一些值scrollFlags来控制其中的视图如何折叠。任何人都可以清楚地标出这些标志之间的区别吗:

  • 滚动
  • 始终输入
  • exitsUntilCollapsed
  • enterAlwaysCollapsed
  • 始终输入

当我们同时将这些标志设置为Toolbar和CollapsingToolbarLayout时,它们如何工作。

android android-collapsingtoolbarlayout

5
推荐指数
2
解决办法
2144
查看次数

在 java 9 中从模块类调用非模块类

我试图从模块类调用非模块类。我创建了一个文件夹结构

moduledemo > allclasses > moduleC > packageC > MyMethods.class
Run Code Online (Sandbox Code Playgroud)

是我的模块类文件的路径

moduledemo > moduleC > packageC > MyMethods.java 
Run Code Online (Sandbox Code Playgroud)

moduledemo > nomodule > packageD > DemoNoModule.class
Run Code Online (Sandbox Code Playgroud)

是我调用的无模块类MyMethods.java

我能够编译 DemoNoModule 文件。我能够将 MyMethods.java 编译到 allclasses 文件夹中moduleC

当我运行 MyMethods 时,出现错误moduleC not found。有人可以更新吗?我正在使用以下命令来运行

java --module-path allclasses -m moduleC/packageC.MyMethods
Run Code Online (Sandbox Code Playgroud)

两个文件代码 -> 非模块类

package packageD;

public class DemoNoModule {
    public void showD() {
        System.out.println("this is show of D in No Module");
    }
}
Run Code Online (Sandbox Code Playgroud)

模块类调用类

package packageC;
import packageD.*;

public class MyMethods …
Run Code Online (Sandbox Code Playgroud)

java java-9 java-module

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

向PendingIntent添加标志

当我们将0作为标志传递给PendingIntent时,如下所示:

PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);
Run Code Online (Sandbox Code Playgroud)

它是否遵循任何标志规则意味着默认情况下0对应于任何标志.

如果我们创建另一个PendingIntent为

 PendingIntent pii=PendingIntent.getActivity(this, 1, i, 0);
Run Code Online (Sandbox Code Playgroud)

它是否与之前相同,如果我对Intent中的数据进行任何更改,它现在是否与Intent中的新数据相对应,或者仍然具有旧数据.

我面临的另一个问题是我试图检查旗帜

PendingIntent.FLAG_NO_CREATE
Run Code Online (Sandbox Code Playgroud)

我写了以下代码:

Intent i=new Intent(this,NotifResult.class);

        i.putExtra("number",50);
        PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0);
NotificationCompat.Builder nb=new NotificationCompat.Builder(this);
        nb.setSmallIcon(R.drawable.ic_launcher);
        nb.setTicker("ticker is here");
        nb.setWhen(System.currentTimeMillis())
        .setContentTitle("just the title")
        .setContentText("and the description")
        .setAutoCancel(true)
        .setDefaults(Notification.DEFAULT_ALL)
        .setContentIntent(pi);


Notification notif=nb.build();
        NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(11, notif);

        i.putExtra("number",80);

        PendingIntent pisecond=PendingIntent.getActivity(this, 1, i, PendingIntent.FLAG_NO_CREATE);

        if(pi.equals(pisecond))
            Log.v("check","they are equal");
        else
            Log.v("check", "they are not equal");

        notif.contentIntent=pisecond;

        nm.notify(11, notif);
Run Code Online (Sandbox Code Playgroud)

根据文档,如果存在existign对象,PendingIntent.FLAG_NO_CREATE不会创建任何新对象.我在NotifResult活动中打印数字的值,其中数字值将是80而不是50,因为它应该使用具有旧值的现有意图(根据我的理解).明确更新为什么输出将来80.日志显示对象与预期的一样.

谢谢

android android-pendingintent

3
推荐指数
1
解决办法
3387
查看次数

Flutter :- 用相机拍照

我是 Flutter 的新手,并编写了以下代码用于在 Image 上显示捕获的图像。但是,相机预览未显示在我的手机上并且圆形指示器不断旋转。我无法查看相机。

import 'dart:io';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

class CameraDemo extends StatefulWidget {
  @override
  _CameraDemoState createState() => _CameraDemoState();
}

class _CameraDemoState extends State<CameraDemo> {
  CameraController _control;
  Future<void> _future;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _initApp();
  }

  void _initApp() async
  {
    WidgetsFlutterBinding.ensureInitialized();
    final cameras = await availableCameras();
    final firstCam = cameras.first;

    _control = CameraController(
      firstCam,
      ResolutionPreset.high,
    );

    _future = _control.initialize();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _control.dispose(); …
Run Code Online (Sandbox Code Playgroud)

flutter

3
推荐指数
1
解决办法
2260
查看次数

优先使用广播接收器

我们可以优先使用吗?

android:priority 
Run Code Online (Sandbox Code Playgroud)

Context.sendBroadcast
Run Code Online (Sandbox Code Playgroud)

也或它会给出不同的结果

Context.sendOrderedBroadcast
Run Code Online (Sandbox Code Playgroud)

谢谢

android

2
推荐指数
1
解决办法
729
查看次数