小编ADM*_*ADM的帖子

列表适配器与回收视图适配器

我正在寻找在 android中使用列表适配器回收视图适配器的区别。使用它们时的性能、优缺点有什么不同。

android android-recyclerview

7
推荐指数
3
解决办法
1495
查看次数

在webview中选择元素

我在我的Android应用程序中实现了一个webview,并尝试在用户点击布局时突出显示或标记元素.

webview初始化如下:

myWebView.getSettings().setJavaScriptEnabled(true);
//myWebView.getSettings().setGeolocationEnabled(true);
//myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.setWebViewClient(new WebViewController());
Run Code Online (Sandbox Code Playgroud)

尝试标记用户点击的元素,例如在此屏幕截图中:

用点选择

我通过jsoup获取所有页面div:

doc = Jsoup.connect(url).get();
final Elements alldivs = doc.select("div");
ArrayList<String> list = new ArrayList<String>();
for (org.jsoup.nodes.Element e : alldivs) {
if (!e.id().equals(""))
list.add(e.id());
}
Run Code Online (Sandbox Code Playgroud)

但是如何将选择标记为上面的照片,然后从div id中选择标记的内容.

如何制作这样的东西?

java android webview

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

如何在ROOM DB中存储货币?

我有实体:

@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)

android android-room

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

Google Play服务地图中的java.lang.StackOverflowError

我注意到我的应用程序中StackOverflow崩溃的数量有所增加,这些崩溃似乎都反映在Google Play服务地图上.我目前正在使用15.0.1版(com.google.android.gms:play-services-maps:15.0.1) - 但这是在两周前我还在使用15.0.0时开始的.有几次崩溃,但是当从地图代码(被混淆)处理Hashmaps或Arrays时,它们都会导致StackOverflows.崩溃的一些例子(我只是将堆栈跟踪复制到了模糊映射代码的位置):

Fatal Exception: java.lang.StackOverflowError: stack size 1038KB
   at java.util.HashMap.remove(HashMap.java:617)
   at com.google.maps.api.android.lib6.gmm6.util.e.d(:com.google.android.gms.dynamite_dynamitemodulesb@12685021@12.6.85 (040306-197041431):29)

Fatal Exception: java.lang.StackOverflowError
   at java.util.ArrayList$ArrayListIterator.(ArrayList.java:551)
   at java.util.ArrayList.iterator(ArrayList.java:548)
   at java.util.Collections$UnmodifiableCollection$1.(Collections.java:953)
   at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:952)
   at com.google.maps.api.android.lib6.common.i.iterator(:com.google.android.gms.dynamite_dynamitemodulesb@12685002@12.6.85 (000304-197041431):25)

Fatal Exception: java.lang.StackOverflowError: stack size 8MB
   at java.util.HashMap.createEntry(HashMap.java:826)
   at java.util.HashMap.addEntry(HashMap.java:813)
   at java.util.HashMap.put(HashMap.java:436)
   at com.google.maps.api.android.lib6.gmm6.util.e.b(:com.google.android.gms.dynamite_dynamitemodulesb@12685020@12.6.85 (040304-197041431):17)

Fatal Exception: java.lang.StackOverflowError: stack size 8MB
   at java.util.HashMap.removeEntryForKey(HashMap.java:597)
   at java.util.HashMap.remove(HashMap.java:584)
   at com.google.maps.api.android.lib6.gmm6.util.e.d(:com.google.android.gms.dynamite_dynamitemodulesb@12685023@12.6.85 (040400-197041431):29)


Fatal Exception: java.lang.StackOverflowError: stack size 8MB
   at java.util.ArrayList.(ArrayList.java:170)
   at com.google.maps.api.android.lib6.common.i.(:com.google.android.gms.dynamite_dynamitemodulesb@12685020@12.6.85 (040304-197041431):9)
Run Code Online (Sandbox Code Playgroud)

我还在混淆的地图代码中直接进行了许多其他崩溃.

其他一些信息:地图不在我的应用程序的主流程中,因此只有大约8%的用户使用它 - 每天大约200个左右的呼叫.今天是迄今为止最严重的62次崩溃影响了13个用户 - 两天前它发生了42次崩溃,其他大多数时间我都没有崩溃.

受影响的操作系统版本:7.0,6.0.1,4.4.2,7.1.1,4.1.2,5.1,4.3

设备:三星,索尼,联想,Moto E3(无论是什么)和华为.

任何帮助或指针都会有用!

android google-maps-android-api-2

5
推荐指数
0
解决办法
706
查看次数

在 build.gradle 中使用 java 类

嗨,也许这是一个愚蠢的问题,但我对 groovy 和 gradle 不太熟悉,无法得到确切的答案。

  public class Config{
   public static final String APPLICATION_ID="com.app.dracula";
   public static final int VERSION_CODE=1;
    public static final String VERSION_NAME="1.0.0";
}
Run Code Online (Sandbox Code Playgroud)

我有上面的课。我可以使用这个类build.gradle来分配所有字段吗(注意字段名称)。

我知道我可以BuildConfigFieldproperties我现在正在做的文件中创建。但出于好奇,有没有办法在 .java 类或接口中使用build.gradle?我可以实现类似的东西吗?

 defaultConfig {
    applicationId Config.APPLICATION_ID
    minSdkVersion 16
    targetSdkVersion 26
    versionCode Config.VERSION_CODE
    versionName Config.VERSION_NAME
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
Run Code Online (Sandbox Code Playgroud)

不要被上面的代码所迷惑,这只是我想要实现的隐喻。

android build.gradle android-gradle-plugin

5
推荐指数
0
解决办法
851
查看次数

从KOTLIN的图库中选择多个图像(想要图像路径)

我正在制作一个应用程序,用于制作来自多个图像的视频kotlin.我有很多java代码,但无法将其转换为kotlin代码.Alwayse错了cursor.getString(column_index) must not be null.
我只是初学者Kotlin.所以任何人都可以为我的问题提供简短的解决方案

val cursor = contentResolver.query(uri,  filePathColumn, null, null, null)
 cursor!!.moveToFirst()
 val columnIndex = cursor.getColumnIndex(filePathColumn[0])
Run Code Online (Sandbox Code Playgroud)

android kotlin

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

如何在Android 10中从后台启动活动?

我正在构建一个Android应用,需要从后台开始活动。我正在使用ForegroundStarter来扩展Service来完成此任务。我有一个活动Adscreen.class,需要从我的前台服务中运行。活动Adscreen.class在除Android 10以外的所有Android版本上都可以正常运行(从后台开始)。

ForeGroundStarter.class

public class ForeGroundStarter extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }



    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("sK", "Inside Foreground");

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("sK", "Inside Foreground onStartCommand");
        Intent notificationIntent = new Intent(this, Adscreen.class);
        PendingIntent pendingIntent =
                PendingIntent.getActivity(this, 0, notificationIntent, 0);


        Notification notification =
                null;

        //Launching Foreground Services From API 26+

        notificationIntent = new Intent(this, Adscreen.class);
        pendingIntent =
                PendingIntent.getActivity(this, 0, notificationIntent, 0);

        if (Build.VERSION.SDK_INT >= …
Run Code Online (Sandbox Code Playgroud)

android foreground-service

5
推荐指数
4
解决办法
288
查看次数

闹钟经理在 24 小时后不工作,一小时后服务终止

public static WorkInfo.State getStateOfWork() {

    if (WorkManager.getInstance().getWorkInfosForUniqueWork("affirmation").get().size() > 0) {
        return WorkManager.getInstance().getWorkInfosForUniqueWork("affirmation")
                .get().get(0).getState();
        // this can return WorkInfo.State.ENQUEUED or WorkInfo.State.RUNNING
        // you can check all of them in WorkInfo class.
    } else {
        return WorkInfo.State.CANCELLED;
    }
} catch (ExecutionException e) {
    e.printStackTrace();
    return WorkInfo.State.CANCELLED;
} catch (InterruptedException e) {
    e.printStackTrace();
    return WorkInfo.State.CANCELLED;
}
}

public static void createWorkRequest() {
Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder
        (MyWorkManager.class, 30, TimeUnit.MINUTES)
        .setConstraints(constraints)
        .build();
WorkManager.getInstance()
        .enqueueUniquePeriodicWork("affirmation", ExistingPeriodicWorkPolicy.REPLACE, periodicWorkRequest);

}
Run Code Online (Sandbox Code Playgroud)

android alarmmanager android-workmanager

5
推荐指数
0
解决办法
24
查看次数

在 android studio 中以编程方式删除按钮单击上的布局

我在单击按钮时添加布​​局。

 private void addLayout() {
    layout2 = LayoutInflater.from(mContext).inflate(R.layout.product_layout, mLinearLayout, false);
    productAuto = (AutoCompleteTextView) layout2.findViewById(R.id.tv_product);
    qtyEditText = (EditText) layout2.findViewById(R.id.prod_qty);
    prodPriceEditText = (EditText)layout2.findViewById(R.id.prod_price);
    prodSpecsEditText = (EditText)layout2.findViewById(R.id.prod_specs);
    removeProduct = (Button)layout2.findViewById(R.id.btn_rmv);
    mLinearLayout.addView(layout2);
    setProd();
    this.initListenersPrd(getActivity());
}
private void initListenersPrd(final Context context) {
    productAuto.setOnItemClickListener((parent, view, position, id) -> {
        String newName = parent.getItemAtPosition(position).toString();
        ProductDetail productDetail = mProductManager.getProductByPrdName(newName);
        if (productDetail != null) {
           this.prodPriceEditText.setText(productDetail.getPrice());
           this.prodSpecsEditText.setText(productDetail.getProductSpec());
        }
    });

    removeProduct.setOnClickListener(v -> {
       if (mLinearLayout.getChildCount()>0)
       {
           ((LinearLayout)mLinearLayout.getParent()).removeView(mLinearLayout);
       }

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

现在我想从应用程序中删除特定的产品表单,因此我已((LinearLayout)mLinearLayout.getParent()).removeView(mLinearLayout);单击“删除”按钮。但它删除了动态添加的整个布局。

图形用户界面

在此输入图像描述

正如您在上图中看到的,我添加了 4-5 个产品布局,但是当我单击“删除”按钮时,我删除了所有布局。

更新1

我在主布局中添加了以下布局,然后以编程方式调用其中的产品布局

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout android-view

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

如何清理房间数据库?

我如何RoomDatabase为我的应用程序进行 VACUUM?我围绕 Room 构建整个应用程序,在某个时刻,一张大表会定期删除,然后再次填充。

我尝试使用查询创建一个额外的 DAO 接口:

@Dao
public interface GenericDao {
    @Query("VACUUM")
    void vacuum();
}
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Error:(13, 10) error: UNKNOWN query type is not supported yet. You can use:SELECT, UPDATE, DELETE
Run Code Online (Sandbox Code Playgroud)

有解决方法吗?

基本上我需要的是,一旦我的表完全清空,自动增量就会再次从 1 开始。

我对数据库设计相当陌生,所以请理解这是否违反最佳实践。是的:我用尽了谷歌和我所知道的所有其他平台。

提前谢谢了!

performance android android-room

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