这是我的Profile.java文件,我想在其中添加"项目1"单击时它必须与我的custom.java文件关联。
package com.haider.first;
public class Profile
extends ListActivity
implements OnItemLongClickListener {
Activity activity;
//on create method
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
//Registering list for context menu
activity = this;
ListView lv = (ListView) findViewById(android.R.id.list);
registerForContextMenu(lv);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.profile)));
}
//this is code for create context menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
// this is code for selecting context item to perform desired actions
@Override
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()) {
case R.id.item1:
// Here i need code from which after click custom.java will be selected or choosen
case R.id.item2:
startActivity(new Intent(Profile.this, Custom.class));
return true;
default:
return super.onContextItemSelected(item);
}
}
//This is code for Enable Single CLick while opening Context Menu
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
activity.openContextMenu(l);
super.onListItemClick(l, v, position, id);
}
//This code disbale long click
@Override
public boolean onItemLongClick(AdapterView<?> enter code here parent, View view, int position, long id) {
// TODO Auto-generated method stub
activity.closeContextMenu();
return false;
}
}
用于实现所有设置的custom.java文件的代码
public class Custom
extends Activity {
private SeekBar mediaVlmSeekBar = null;
private AudioManager audioManager = null;
//Oncreate Method
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.custom_sett);
initControls();
// Code for vibration but my app vibrates after short time intervals even it is closed
ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton1);
tb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//this method is for changing status of mutiple options.
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked) {
Intent vibintent = new Intent(getApplicationContext(), Vibration.class);
startService(vibintent);
} else {
}
}
});
//Code for Controlling Volume, here i am facing issue that i cannot change volume of my app with device buttons
/Here is my code for Volume
private void initControls () {
// TODO Auto-generated method stub
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mediaVlmSeekBar = (SeekBar) findViewById(R.id.seekBar1);
mediaVlmSeekBar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
//Set the progress with current Media Volume
mediaVlmSeekBar.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
try {
mediaVlmSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
..........
现在我的问题是当用户选择名为&#34; General&#34;它会选择custom.java文件而不打开。换句话说,当用户选择General时,将自动选择音量,振动,铃声等的整个设置。