Android简单的应用程序无法启动,不知道为什么

时间:2012-07-12 17:02:05

标签: android button save volume seekbar

我对这个简单的程序有一个问题(实际上这是单个Activity / Class)。这不会给我带来任何错误,它只是在运行时无法在模拟器/设备中启动。 它包含一个seekBar(Ringer音量栏)和一个OK按钮(在搜索栏后保存更改)。我不想要一个实时的seekBar(我的意思是在seekBar中搜索,自动更改音量)

这是代码

public class Vol extends Activity {

public static final String TYPE = "TYPE";


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

    Bundle extras  = getIntent().getExtras();
    final int volumeType = extras != null ? extras.getInt(TYPE) : -1;
    final AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    String title = "Unknown Volume";

    if (volumeType != -1) {
        switch(volumeType) {
        case AudioManager.STREAM_RING:

            break;
        }

        setContentView(R.layout.main);
        setTitle(title);
        final SeekBar systemSeek = (SeekBar) findViewById(R.id.volume_bar);
        systemSeek.setMax(audio.getStreamMaxVolume(volumeType));
        systemSeek.setProgress(audio.getStreamVolume(volumeType));
        systemSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar seekBar) {
                final int setVolFlags = AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI;
                audio.setStreamVolume(volumeType,seekBar.getProgress(), setVolFlags);

            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub

            }
        });

        Button ok  = (Button) findViewById(R.id.ok_button);
        ok.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                if (volumeType == AudioManager.STREAM_RING){
                    audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                }
                finish();

            }
        });

    } else {
        finish();

    }

}

}

你能帮帮我吗? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

剪切 -

setContentView(R.layout.main);

并粘贴在下面 -

super.onCreate(savedInstanceState);