小编Ack*_*man的帖子

片段生命周期中是否在onAttach上调用?

onAttach在Fragment-Activity生命周期中何时被调用?

我知道片段生命周期,但到底是什么时候?

是在启动片段对象还是调用片段管理器时?

java android android-fragments

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

模块,库,jar,库项目,gradle项目,aar和jar之间的区别

我在一家拥有由离岸团队开发的Android移动应用程序的公司工作.我可以访问GitHub存储库.

我正在逐块拼凑Android应用程序,它给了我地狱.

我如何区分模块,库,jar,库项目,gradle项目,aar和jar.有人可以给我一个实际的定义.不是出于一个疯狂的谷歌搜索.我也有谷歌.

PS是的我是一个菜鸟,并不以此为荣.

android gradle android-studio

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

如何在 styled 中使用同级选择器 css

我有一个样式组件,如下所示:

import styled from 'styled-components';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';

export const CategoryList = styled(List)`
`;
//this is what i want to change
export const CategoryListItem = styled(ListItem)`
  border-top: 2px solid #f4f4f4;
`;

export const CategoryListItemText = styled(ListItemText)`
  padding-left: 5px;
`;

export const ListItemHeading = styled(ListItem)`
  background-color: #f4f4f4;
`;
Run Code Online (Sandbox Code Playgroud)

在这种情况下我如何使用兄弟姐妹 & + & ?

我想实现类似的目标:

li + li {
border-top: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?

javascript css ecmascript-6 reactjs styled-components

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

在Google地图片段中显示当前位置

我目前正在制作一个带有谷歌地图的片段.一旦用户访问该片段,他的地图应该缩放并关注他的位置.但是,它显示的是世界地图而不是附近的位置(靠近用户):

@SuppressWarnings("unused")
public class DeferredMapFragment extends MapFragment implements GoogleMap.OnCameraChangeListener, OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
            LocationListener {
        private static final String TAG = "DeferredMapFragment";

    private Deque<Runnable> pendingActions;
    private AbstractMap<Marker, Object> tags;

    private GoogleMap map;
    private LocationRequest mLocationRequest;
    private GoogleApiClient mGoogleApiClient;
    private Location mLastLocation;
    private Marker marker;

    private GoogleMap.OnCameraChangeListener cameraChangeListener = null;

    private boolean isMapReady = false;

    /*
     * INTERNALS
     */

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (getMap() != null) {
            map = getMap();
            getMap().setOnCameraChangeListener(this);
        }
    }

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

maps android google-maps

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

编写一个测试来更改子组件的 prop

*********************更新**************************** ******************

我有一个正在尝试测试的对话框组件。我试图在对话框内设置子组件(TextInput)的“value”属性。我几乎尝试了一切,但似乎没有任何效果。有人能帮我吗?

test('input type returns a text', () => {
const okPressFunction = jest.fn()
const obj = (
  shallow(
    <DialogBox
      title='random title'
      message={lorem}
      type='input'
      isVisible
      onOkPress={okPressFunction}
      onRequestClose={noop}
    />
  )
)
// obj.dive().find('TextInput').setProps({ value: 'hi' })
// obj.update()
// console.log(obj.dive().find('TextInput').prop('value'))
obj.find('TextInput').simulate('change', {
  target: { value: 'hello' },
})
obj.update()
console.log(obj.dive().find('TextInput').prop('value'))
  })
})
Run Code Online (Sandbox Code Playgroud)

console.log(obj.html()) 转储是:

  <Component
  transparent={true}
  animationType="fade"
  visible={true}
  onRequestClose={[(Function: noop)]}
  hardwareAccelerated={false}
>
  <View
    style={{
      backgroundColor: "#33333340",
      width: "100%",
      height: "100%",
      justifyContent: "center",
      alignItems: "center",
    }}
  >
    <View
      style={{
        backgroundColor: "white", …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-native enzyme

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

类型错误:无法在玩笑测试中读取未定义的属性“原型”

我有一个使用反应导航的附加信息组件:

export class AdditionalInfo extends NavigationPureComponent {
  static navigationOptions = ({ navigation }) => ({
    headerLeft: <Button icon="close" onPress={() => navigation.goBack(null)} />,
  })

  buildNavigator = () => {
    const { extendedDescriptions } = this.nav.params
    const tabs = {}

    extendedDescriptions.forEach(({ caption, description }, index) => {
      tabs[`Tab${index}`] = {
        screen: () => (
          <ScrollView style={{ backgroundColor: color('white') }}>
            <Wrapper style={{ paddingTop: spacing() }}>
              <SafeAreaView>
                <Html html={description} />
              </SafeAreaView>
            </Wrapper>
          </ScrollView>
        ),
        navigationOptions: {
          title: caption,
        },
      }
    })

    return createMaterialTopTabNavigator(tabs, { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-native enzyme

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

检查互联网连接OKHTTP

我使用以下代码进行api调用,并根据收到的响应将用户定向到页面.我如何检查互联网连接?

我正在使用一个OK HTTP客户端,我的代码如下所示:

 button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String url = "https://xxxxxxxx/" + orderLineId;
            JSONObject jSon = new JSONObject();
            try {
                jSon.put("prescription_xxxxx", prescriptionIntervalId);
                jSon.put("prescription_xxxxxxx", false);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            String data = jSon.toString();
            RequestBody body = RequestBody.create(JSON, data);
            Request request = new Request.Builder()
                    .url(url)
                    .addHeader("Content-Type", "application/json")
                    .addHeader("Authorization", token)
                    .addHeader("Accept", "application/json")
                    .put(body)
                    .build();

            client.newCall(request).enqueue(new Callback() {@Override
                public void onFailure(Request request, IOException e) {

                    AlertDialog.Builder dialog = new AlertDialog.Builder(AutoRefillActivity.this);
                    dialog.setMessage("Something went wrong. Check connection.")
                            .setCancelable(false) …
Run Code Online (Sandbox Code Playgroud)

java https android android-studio okhttp

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

应用程序单例在Android中使用

我有一个facebook初始化sdk调用,我需要它来初始化应用程序启动的时刻:

我想使用我的Application类来做到这一点.例如:

public class App extends Application {

@Override
public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
}
}
Run Code Online (Sandbox Code Playgroud)

我有facebook登录按钮的主要活动:

public class MainActivity extends AppCompatActivity {
@BindView(R.id.login_button)
LoginButton loginButton;

private CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

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

如何调用我的应用程序单例?如何使其onCreate()工作?

java singleton android facebook-sdk-3.0

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

开玩笑的测试失败,带有引用和表单

我有一个搜索栏组件,看起来像:

  render () {
    const { onChangeTextInput } = this.props
    return (
      <Form
        name="searchForm"
        ref={(ref) => {
          this.searchForm = ref
        }}
      >
        <TextInput
          noSpacing
          placeholder={t('search')}
          name="search"
          validate="text"
          icon={this.icon}
          onChangeTextCallback={() => {
            onChangeTextInput(this.searchForm.values)
          }}
        />
        )
      </Form>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用浅渲染和玩笑来运行单元测试以测试以下情况”

  1. 用户在文本输入中键入字符
  2. 将触发一个回调方法,该方法为用户提供文本作为参数。

我正在运行的测试表示为:

 test('SearchBar returns value on text change', () => {
        const onChangeFunction = jest.fn()
        const obj = shallow(
          <SearchBar onChangeTextInput={onChangeFunction} />
        )
        obj.find('TextInput').props().onChangeTextCallback('h')
        expect(onChangeFunction).toHaveBeenCalledWith('h')
      })
Run Code Online (Sandbox Code Playgroud)

我收到一个奇怪的错误说明:

TypeError: Cannot read property 'values' of undefined

  51 |           icon={this.icon}
  52 | …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-native enzyme

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

在UILabel中插入超链接

我从文本形式的api中得到了回复,我希望扫描该文本中的"Planned Parenthood health center",并在该词上插入一个超链接,重定向到plannedparenthood.org/health-center门户.

我的方法:

NSString *text = response.content;
text = [text stringByReplacingOccurrencesOfString:@"Planned Parenthood health center" 
                                       withString:@"<a href=\"http://www.plannedparenthood.org/health-center\">Planned Parenthood health center</a>"];
Run Code Online (Sandbox Code Playgroud)

虽然文本上的链接正在被替换.它正在被取代

<a href=\"http://www.plannedparenthood.org/health-center\">Planned Parenthood health center </a>
Run Code Online (Sandbox Code Playgroud)

有什么不对,为什么我没有在那里得到任何链接?我做错了什么我还将用户启用的交互设置为YES

xcode objective-c hyperlink nsstring uilabel

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

JSON.parse给出了意外的令牌错误

我打电话给api时收到这些数据

[{"DispatchNo":"xxxxx","DispatchDate":"xxxxxxx","Complete":"xxx","CustomerID":"xxxxx","Name":"xxxxxx","Contact":"","Phone":"xxxxx","ShipPhone":"xxxx","PurchaseOrder":"xxxx","OrderLoads":"5","OrderQty":"125","FreightUnitID":"x 
Run Code Online (Sandbox Code Playgroud)

我的controoller.js代码表示失败的是:

var jsonString = result.data.replace(/\\/g, "\\");
                var orderFromApex = JSON.parse(jsonString);
                orderFromApex = orderFromApex.substring(0);
                console.log(orderFromApex);
                //orderFromApex += '"';
                orderFromApex = JSON.parse(orderFromApex);
                console.log(orderFromApex);
Run Code Online (Sandbox Code Playgroud)

我收到错误语法错误:JSON在JSON.parse()的位置898处的JSON中出现意外的令牌C我相信它在orderFromApex = JSON.parse(orderFromApex)失败了.我也是我在上面发布的控制台记录orderFromApex.到底是怎么回事?我的JSON响应有问题吗?

javascript json angularjs

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