Android setContentView()显示为空白

时间:2014-01-15 20:52:47

标签: java android layout user-interface

因此,当我在操作栏上使用一些图标时,我将内容视图更改为另一个布局。现在,当尝试返回我的activity_main.xml文件时,整个内容显示为空白。为什么会出现这种情况的任何可能的解决方案?

注意:当案例为R.id.action_settings

时,switch语句中会出现更改
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        if (onMainThread) {
            if (MusicInvoker.currentSong != null) {
                LayoutInflater inflator = getLayoutInflater();
                View view = inflator.inflate(R.layout.player, null, false);
                view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left));
                onMainThread = false;

                setContentView(view); 

                TextView artist = (TextView) findViewById(R.id.artist_name);
                TextView title = (TextView) findViewById(R.id.songName);

                artist.setText(MusicInvoker.currentSong.artist);
                title.setText(MusicInvoker.currentSong.title);

                mi.invokeLater();
            }

            return true;
        } else {
            onMainThread = true;
            LayoutInflater inflator = getLayoutInflater();
            inflator.inflate(R.layout.activity_main, null);
            setContentView(R.layout.activity_main);
        }

        return true;

    case R.id.top_ten:
        LayoutInflater inflator = getLayoutInflater();
        View view = inflator.inflate(R.layout.top_ten, null, false);

        setContentView(view);

        ListView lview = (ListView) findViewById(R.id.tten);
        TopTenParser ttp = new TopTenParser();
        TopTenAdapter tta = new TopTenAdapter(this, ttp.returnVals());
        lview.setAdapter(tta);
        view.startAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.slide_in_left));
        onMainThread = false;

        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案