小编Vin*_*eet的帖子

ViewPager的FragmentActivity:方向更改崩溃

嗨,大家好我在FragmentActivity中使用过ViewPager.方向改变时我会崩溃.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    context = this;
    loadInitialData();
    setActionBar();
    initializeUiComponents();
}

private void initializeUiComponents() {
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    }
Run Code Online (Sandbox Code Playgroud)

我的数据是从数据库动态传递的,我必须调用Sysnctask,它在onResume()中从数据库获取数据.这是Asynctask的onPostExecute().

protected void onPostExecute(Void result) {

            mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
            mViewPager.setAdapter(mSectionsPagerAdapter);
        }
        mSectionsPagerAdapter.notifyDataSetChanged();
        }
}
Run Code Online (Sandbox Code Playgroud)

添加FragmentAdapterCode:

public class SectionsPagerAdapter extends FragmentPagerAdapter {
    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page. …
Run Code Online (Sandbox Code Playgroud)

android orientation android-viewpager android-fragmentactivity

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

如何从Android中的位图对象获取mime类型?

我想获取位图对象的mime类型。其实我已经压缩了位图使用

bitmap.compress (Bitmap.CompressFormat.PNG , 100, stream);
Run Code Online (Sandbox Code Playgroud)

现在,我要交叉检查格式,outBounds和内存空间大小。但是我不想做一个冗长或乏味的工作。将其转换回流,然后使用带选项的BitmapFactory将其再次转换为BItmap。

android bitmap mime-types

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