小编arj*_*jun的帖子

如何使用 useLazyQuery() 在每次点击时执行查询

使用我的useLazyQuery()钩子@apollo/react-hooks可以在单击按钮时执行查询。但是我不能使用它在连续点击时执行相同的查询。

export default ({ queryVariables }) => {
  const [sendQuery, { data, loading }] = useLazyQuery(GET_DIRECTION, {
    variables: queryVariables
  });

  return <div onClick={sendQuery}>Click here</div>;
}
Run Code Online (Sandbox Code Playgroud)

在上面sendQuery只执行一次。

reactjs react-apollo apollo-client react-apollo-hooks

14
推荐指数
1
解决办法
4299
查看次数

在android中为库项目设置不同的主题

在包含库项目的android项目中,我需要在主应用程序和库的清单中设置不同的主题.就像我需要在主项目中设置以下主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorPrimary">@color/grey</item>
  <item name="colorPrimaryDark">@color/black</item>
  <item name="colorAccent">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)

以及图书馆项目下面的那个

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="colorPrimary">@color/blue</item>
  <item name="colorPrimaryDark">@color/red</item>
  <item name="colorAccent">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)

主应用程序样式会覆盖库项目样式.当我为样式指定不同的名称时,它会抛出明显的合并冲突错误.

以下是主应用程序的清单

<application
  android:name=".MyApp"
  android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)

这个是图书馆的

<application
  android:allowBackup="true"
  android:label="@string/app_name"
  android:supportsRtl="true"
  android:theme="@style/AppTheme"
  >
Run Code Online (Sandbox Code Playgroud)

android styles android-manifest android-library android-theme

10
推荐指数
1
解决办法
5169
查看次数

Android - onTextChanged()在手机方向更改时调用

我尝试使用实现搜索EditText.每当在EditText请求中键入文本时,都会在onTextChanged()方法中使用键入的文本发送.当我使用显示的结果更改手机的方向时,将onTextChanged()使用相同的文本再次调用方法.如何避免onTextChanged()在方向更改时对方法进行冗余调用.

    public void onTextChanged(CharSequence s, int start, int before, int count) {

    final String enteredKeyword = s.toString();


    if(isFragmentVisible && !enteredKeyword.equals("")) {

    searchTimer.cancel();
    searchTimer = new Timer();
    TimerTask searchTask = new TimerTask() {
    @Override
    public void run() {
          searchUser(enteredKeyword);
    }
};
searchTimer.schedule(searchTask, 1500);
Log.i("", enteredKeyword);
}
}
Run Code Online (Sandbox Code Playgroud)

android android-edittext

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

Android测试发布版本

我试图测试应用程序的发布版本.所以我build.gradle在我的应用程序中添加了以下配置.但这并没有产生任何影响.测试始终在调试版本上运行

android {
 compileSdkVersion 24
 buildToolsVersion "24.0.0"

defaultConfig {
  applicationId "com.****.****"
  minSdkVersion 15
  targetSdkVersion 22
  versionCode 1
  versionName "1.0 Beta"
  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

testBuildType "release"

signingConfigs {
  release {
    keyAlias '******'
    keyPassword '*****'
    storeFile file('path to keystore')
    storePassword '*****'
  }
}

buildTypes {
  release {
    minifyEnabled true
    debuggable true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    signingConfig signingConfigs.release
   }
   debug {
     multiDexEnabled true
   }
  }
}
Run Code Online (Sandbox Code Playgroud)

当在其他SO线程中搜索答案时,我发现testBuildType "release"将在发布版本上运行测试,但它不起作用

testing android android-testing android-espresso

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

Android相机的预览大小和图片大小有什么区别

在使用相机的应用程序中,我需要显示相机的预览,我可以通过获取所有支持的预览尺寸并找到最佳预览尺寸来设置预览尺寸.我还应该为相机设置最佳图片尺寸吗?如果是这样,预览大小和图片大小有什么区别?

目前我使用以下内容来查找最佳预览尺寸

int minDiff = Integer.MAX_VALUE;
for (SizePair sizePair : validPreviewSizes) {
  Size size = sizePair.previewSize();
  int diff =
      Math.abs(size.getWidth() - desiredWidth) + Math.abs(size.getHeight() - desiredHeight);
  if (diff < minDiff) {
    selectedPair = sizePair;
    minDiff = diff;
  }
}
Run Code Online (Sandbox Code Playgroud)

使用此方法会在某些手机中提供错误的预览尺寸.有人可以建议一个更好的逻辑来获得最佳的preivew大小?

camera android android-camera

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