0

我对这个简单的程序有疑问(实际上这是单个活动/类)。这不会返回任何错误,它只是在运行它时不会在模拟器/设备中启动。它包含一个 seekBar(Ringer Volume Bar) 和一个 OK 按钮(在搜索 Bar 后保存更改)。我不想要实时的 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();

    }

}

}

请你帮助我好吗?提前致谢!

4

1 回答 1

0

切 -

setContentView(R.layout.main);

并粘贴在下面 -

super.onCreate(savedInstanceState);
于 2012-07-12T17:11:34.757 回答