小编Bar*_*tek的帖子

考虑到Java中的当前语言环境,如何检查某个日期是否是周末?

我正在用 Java 编写程序,我需要确定某个日期是否是周末。然而,我需要考虑到,在不同的国家,周末是在不同的日子,例如在以色列是周五和周六,而在一些伊斯兰国家是周四和周五。有关更多详细信息,您可以查看这篇 Wikipedia 文章。有没有简单的方法来做到这一点?

java datetime date dayofweek weekend

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

ListView项目布局在targetSdkVersion ="17"和targetSdkVersion ="18"之间有所不同

我刚刚将Android SDK更新到版本18并修改了我正在使用它而不是版本17的项目.事实证明我的ListView现在看起来很不一样.但是,只需将清单文件中的targetSdkVersion从18切换到17,即可再次使用.

我设法通过在Eclipse中创建一个新的Android项目并将主活动更改为最基本的ListActivity实现来重现该问题:

public class MainActivity extends ListActivity {

    private static final String[] listItems = new String[] { "list item 1", "list item 2"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, listItems));
    }

}
Run Code Online (Sandbox Code Playgroud)

list_item.xml文件包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="100dip"
        android:background="#ff0000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignBottom="@id/text"
        android:layout_alignTop="@id/text"
        android:background="#88ffffff"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#8c0000ff"
            android:text="@string/button1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dip"
            android:background="#8c00ff00"
            android:text="@string/button2" />
    </LinearLayout>

</RelativeLayout> …
Run Code Online (Sandbox Code Playgroud)

android android-listview

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

Crashlytics 自定义日志何时发送?

我有一个 BaseActivity 作为我所有活动的父级。我想将 Activity 事件(onCreate()、onStart()、onResume() 等)记录到 Crashlytics,因此当发生崩溃时,我知道用户在做什么以及哪些活动当前处于活动状态。我将以下代码添加到要记录的所有方法中:

CrashlyticsCore.getInstance().log(getClass().getSimpleName() + ".onResume()");
Run Code Online (Sandbox Code Playgroud)

我想知道这样做是否是个好主意。是否仅在发生崩溃时发送日志?我不会向服务器发送垃圾邮件并为用户产生不必要的网络呼叫吗?也许有更好的方法来使用 Crashlytics 实现面包屑?

android crashlytics crashlytics-android

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

具有视图绑定的 ComposeView

ComposeView我在 XML 布局文件中添加了一个。我使用视图绑定在我的活动中膨胀此文件。当我尝试调用时binding.myComposeView.setContent { ... },出现以下编译错误:Unresolved reference: setContent。当我查看生成的绑定文件时,可以看到myComposeViewisView和 not的类型ComposeView。当我使用findViewById<ComposeView>(R.id.myComposeView).setContent { ... }时一切正常。为什么绑定没有正确生成?我可以做什么来使用带有 a 的视图绑定ComposeView

android-jetpack-compose android-viewbinding

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