I have a list preference that will allow a user to select which audio codec they wish to use in my Voice Recorder android application.
I would like to set an onClick listener for each item in the list as when it is selected I need to access my main activity and change the MediaRecorder's settings. Currently, I have an onClick listener that only activates when the "Audio Codec" option itself is selected.
Here is my preference activity and below is the current code for the onClick listerner.
final Preference audioCodec = findPreference("codec");
audioCodec.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
System.out.println("Clicked");
return true;
}
});
}
Below are the values that I want the onClick listener to be assigned to rather than just the title "Audio Codec". Is this possible?
<!-- Audio codec list -->
<string-array name="codecListArray">
<item>Audio codec 1</item>
<item>Audio codec 2</item>
<item>Audio codec 3</item>
</string-array>
Please let me know if you need more screenshots or information, thank you.
You can use an OnPreferenceChangeListener
that is triggered each time the preference is changed.
audioCodec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// newValue is the value you choose
return true;
}
});