小编Ben*_*Luk的帖子

如何在Fragment上获取onWindowFocusChanged?

使用导航抽屉使用Android滑动菜单.我知道onWindowFocusChanged有关MainActivity的工作.我该怎么检查它是否有片段聚焦?

有人说我可以传递hasFocus给片段,但我不知道该怎么做.谁能给我一些示例代码?

我想在我的片段上运行↓这个

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
        //I need to do someing.
        method();
    }
}
Run Code Online (Sandbox Code Playgroud)

android fragment

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

如何创建自定义注释以拆分请求参数并收集返回结果?

我有一个方法params是一个大于50000项的列表; 限于业务逻辑,列表必须小于30000,所以我有一个方法在逻辑之前将这个数组拆分为2d数组

public static final <T> Collection<List<T>> partitionBasedOnSize(List<T> inputList, int size) {
        AtomicInteger counter = new AtomicInteger(0);
        return inputList.stream().collect(Collectors.groupingBy(s -> counter.getAndIncrement() / size)).values();
}
Run Code Online (Sandbox Code Playgroud)

这是我目前的解决方案:

public List<Account> getChildrenList(List<Long> ids) {
        List<Account> childrenList = new ArrayList<>();
        Collection<List<Long>> childrenId2dList = PartitionArray.partitionBasedOnSize(childrenIdsList, 30000);
        for (List<Long> list : childrenId2dList) {
            //this is my business logic: start
            childrenList.addAll(accountRepository.getAccounts(list));
            //this is my business logic: end
        }
        return childrenAccountsList;
}
Run Code Online (Sandbox Code Playgroud)

我想在方法的顶部创建一个注释,而不是许多重复的代码(每次检查和讨厌......)

抱歉我的英文不好,我画了一个图:方法叫做> spite array>业务逻辑>收集所有结果>返回 在此输入图像描述

java java-8 java-annotations

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

如何在 Spring 中缓存对象列表?

我有一个名为 getUserById 的方法

@Cacheable(value = "Account", key = "#accountId")
public Account getUserById(Long accountId) {
Run Code Online (Sandbox Code Playgroud)

另一个名为 getUserByIds 的方法

@Cacheable(?????)
public List<Account> getUserByIds(List<Long> accountIds) {
Run Code Online (Sandbox Code Playgroud)

如何通过帐户 ID 缓存所有帐户?谢谢

spring spring-boot spring-cache

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

第一个片段崩溃时的getActivity().getActionBar()

public class MainActivity extends ActionBarActivity {

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

    }

    private void setupViewPager() {
        // TODO Auto-generated method stub
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), FragmentPagerItems.with(this)
                        .add("Home", HomeFragment.class)
                        .add("Message", MessageFragment.class)
                        .add("My", MyFragment.class).create());

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(adapter);
        SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
        final LayoutInflater inflater = LayoutInflater.from(viewPagerTab.getContext());
        final Resources res = viewPagerTab.getContext().getResources();
        viewPagerTab.setCustomTabView(new SmartTabLayout.TabProvider() {
            @Override
            public View createTabView(ViewGroup container, int position,PagerAdapter adapter) {
                ImageView icon = (ImageView) inflater.inflate(R.layout.mainactivity_tab, container, false);
                switch (position) …
Run Code Online (Sandbox Code Playgroud)

android fragment android-actionbar

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

如何在arraylist中指定字段并使用简单的Java 8代码设置为列表?

我有一个名为的列表accountList.这个循环有没有简单的Java 8替代品?

List<Long> accountIdList = new ArrayList<Long>();
for(Account account: accountList){
    accountIdList.add(account.getId());
}
Run Code Online (Sandbox Code Playgroud)

java

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