小编rev*_*ary的帖子

在Android中使用notifyItemRemoved或notifyDataSetChanged与RecyclerView

我正在创建一个使用RecyclerView显示的卡片列表,其中每张卡片都有一个按钮,可以从列表中删除该卡片.

当我使用notifyItemRemoved()删除RecyclerView中的卡时,它会删除项目和动画,但列表中的数据未正确更新.

如果不是这样,我切换到notifyDataSetChanged()然后列表中的项目被删除并正确更新,但然后卡片不动画.

有人有使用notifyItemRemoved()的经验,并知道为什么它的行为与notifyDataSetChanged不同?

以下是我正在使用的一些代码:

private List<DetectedIssue> issues = new ArrayList<DetectedIssue>();

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    if(position >0){
        RiskViewHolder riskHolder = (RiskViewHolder)holder;
        final int index = position - 1;
        final DetectedIssue anIssue = issues.get(index);

        riskHolder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    int index = issues.indexOf(anIssue);
                    issues.remove(anIssue);
                    notifyItemRemoved(index);

                    //notifyDataSetChanged(); …
Run Code Online (Sandbox Code Playgroud)

android android-listview notifydatasetchanged android-recyclerview

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

getHeight for View哪个可见性=已消失

我有一个LinearLayout默认情况下其可见性设置为"Gone",我需要获取此视图的高度,以便在可见时执行滑出动画.如何获得可见状态的总高度,因为View.getHeight在未调用布局时返回零.

<LinearLayout
    android:id="@+id/card_checkin_layout_termsconditionsconfirmation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:gravity="center_horizontal"
    android:background="#d0d0d0"
    android:visibility="invisible"
    android:orientation="vertical" >

    <Button
        android:id="@+id/card_checkin_button_confirmdetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:background="@drawable/shape_checkin_buttons2"
        android:text=">   Confirm your details"
        android:paddingLeft="8dp"            
        android:gravity="left|center_vertical"
        android:textColor="@color/card_checkin_button_textcolor_blue" 
        />

    <Button
        android:id="@+id/card_checkin_button_termsandconditions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:paddingLeft="8dp"            
        android:background="@drawable/shape_checkin_buttons2"
        android:text=">   Terms and Conditions"
        android:gravity="left|center_vertical"
        android:textColor="@color/card_checkin_button_textcolor_blue" 
        />

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

android android-ui android-animation android-layout android-view

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

将MPI与docker容器一起使用

我已经基于Ubuntu 16.04创建了一个docker镜像,并且具有运行MPI所需的所有依赖项.

它在docker-hub上公开:https://hub.docker.com/r/orwel84/ubuntu-16-mpi/

我用这个图像来创建一个MPI容器.我还可以编译一个简单的mpi-hello-world.c(它位于容器内)并用mpirun运行它.

这些是我使用的步骤,(如果你安装了Docker,你也可以重现它们):

  1. docker run -it orwel84/ubuntu-16-mpi bash
  2. (在容器的外壳上) mpirun -np 4 --allow-run-as-root ./mpi_hello_world

你会看到输出:

Hello world from processor 6f9b11cef939, rank 0 out of 4 processors

Hello world from processor 6f9b11cef939, rank 1 out of 4 processors

Hello world from processor 6f9b11cef939, rank 2 out of 4 processors

Hello world from processor 6f9b11cef939, rank 3 out of 4 processors
Run Code Online (Sandbox Code Playgroud)

题:

现在所有上述四个mpi进程都在一个容器内运行.

如何在单个主机上使用mpirun在多个容器上运行?还有我如何使用Docker swarm在swarm的多个节点上运行?

请帮忙.谢谢.

mpi openmpi docker docker-compose docker-swarm

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

getSupportActionBar()使用Robolectric返回null

当我通过Roboelectric和JUnit中的测试用例调用它时,方法getSupportActionBar()返回null.

这是我的简单测试用例:

package com.mobile.test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import android.app.Activity;
import android.content.Intent;
import com.mobile.android.core.R;
import com.mobile.android.core.activity.MainActivity;
import com.mobile.android.core.activity.TestActivity;

@RunWith(RobolectricTestRunner.class)
public class NavigationDrawerTest {
private Activity activity;

@Test
public void testNavigationDrawer() {
    activity = Robolectric.buildActivity(MainActivity.class).create().get();
    String hello = activity.getResources().getString(R.string.drawer_open);
    System.out.println(hello);
    assertEquals(hello, "Menu");
}
}
Run Code Online (Sandbox Code Playgroud)

这是我的Activity类:

public class MainActivity extends ActionBarActivity {
// Drawer related
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
String[] mDrawerOptions;

@Override
public void …
Run Code Online (Sandbox Code Playgroud)

android junit4 robolectric android-actionbar android-support-library

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

关闭设备音量 - iOS

可能重复:
以编程方式静音/静音iOS设备?

我需要以编程方式关闭设备卷.有谁知道吗?

到目前为止,我发现,也许我可以使用AudioSessionSetProperty()函数,并使用属性"kAudioSessionProperty_CurrentHardwareOutputVolume",但此属性只是只读.所以我不确定这是否有效:

float value = 0.0f;
AudioSessionSetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, sizeof(float), &value);
Run Code Online (Sandbox Code Playgroud)

App-Store中已有应用程序执行此操作,例如AutoSilent:

http://itunes.apple.com/nl/app/autosilent/id474777148?mt=8

iphone audio ios4 ios ios5

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

自定义视图无法从View.getContext获取活动句柄

我在活动中有一个自定义视图,我正在使用Application上下文启动.

当我View.getContext()在我的内部调用from CustomView并尝试施放它时:

Activity activity = (Acitivity)View.getContext();
Run Code Online (Sandbox Code Playgroud)

它提供了可以不投的错误Context,从ApplicationActivity.

有没有人在面对这个问题?请帮忙

android android-custom-view android-context android-activity

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

詹金斯无法启动模拟器

我试图在Jenkins服务器上运行模拟器.但我一直收到这个错误,Jenkins无法启动下面错误的模拟器becoz,直到它超时:

[android] Waiting 10 seconds before starting emulator...

$ /opt/android-sdk-linux/platform-tools/adb start-server

* daemon not running. starting it now on port 9666 *
* daemon started successfully *
$ /opt/android-sdk-linux/platform-tools/adb start-server
[android] Starting Android emulator
$ /opt/android-sdk-linux/tools/emulator64-arm -ports 9664,9665 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_320_HVGA_android-19_armeabi-v7a -no-snapshot-load -no-snapshot-save -no-window -no-audio -gpu off

resize2fs 1.42.13 (17-May-2015)
The filesystem is already 51200 (4k) blocks long.  Nothing to do!

$ /opt/android-sdk-linux/platform-tools/adb connect localhost:9665
unable to connect to localhost:9665: Connection refused
[android] Waiting for emulator to …
Run Code Online (Sandbox Code Playgroud)

android android-emulator jenkins jenkins-plugins android-emulator-plugin

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

Keras ImageDataGenerator 用于多个输入和基于图像的目标输出

我有一个模型,它以两个图像作为输入并生成单个图像作为目标输出。

我的所有训练图像数据都位于以下子文件夹中:

  • 输入1
  • 输入2
  • 目标

我可以使用keras中的ImageDataGenerator类和方法flow_from_directorymodel.fit_generator训练网络吗?

我怎样才能做到这一点?因为我遇到的大多数示例都处理单个输入和基于标签的目标输出。

就我而言,我有一个非分类目标输出数据和多个输入。

请帮忙,因为您的建议非常有帮助。

keras tensorflow tensorflow-datasets tf.keras

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

eclipse kepler"无法安装远程市场位置"

我已经下载了最新的eclipse版本,eclipse kepler.

但是当我尝试在eclipse中访问Marketplace或尝试为Android安装ADT插件时,它给了我这个令人毛骨悚然的错误,这让我发疯:

Cannot open Eclipse Marketplace
Cannot install remote marketplace locations: Connection failed

This is most often caused by a problem with your internet connection. Please check your internet connection and retry.
Unable to read repository at http://marketplace.eclipse.org/catalogs/api/p.
Connection reset
Connection failed

This is most often caused by a problem with your internet connection. Please check your internet connection and retry.
Connection reset
Run Code Online (Sandbox Code Playgroud)

eclipse eclipse-plugin eclipse-marketplace eclipse-kepler

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

iOS中的后台应用程序,用于检测来电

我需要在iOS中编写一个后台应用程序来监听iPhone上的来电.

可能吗?谁能提出一些好的指示?

谢谢

iphone xcode objective-c ios4

0
推荐指数
1
解决办法
5530
查看次数

反汇编Android NDK代码

可能重复:
如何从gcc中的C/C++源获得汇编程序输出?

我有一个简单的问题.

我有一些为Android应用程序编写的本机C++代码.

当我在Eclipse中编译项目时,有什么方法可以看到我的GCC编译器生成的汇编代码?

eclipse android gcc arm android-ndk

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