मैं एंड्रॉइड के माध्यम से वरीयता के लिए उचित लेआउट सेट कर सकता हूं: लेआउट विशेषता। एक उदाहरणएंड्रॉइड का उपयोग कर कस्टम वरीयता के लिए लेआउट को तुरंत कैसे करें: लेआउट विशेषता
<Preference android:key="friction" android:title="@string/friction" android:layout="@layout/friction_fragment" android:shouldDisableView="true" android:defaultValue="30" android:enabled="true" android:selectable="true" android:summary="Bite friction"></Preference>
जहां लेआउट
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:text="@string/friction" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"></TextView>
<SeekBar android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/sbFriction"></SeekBar>
<TextView android:text="@string/friction_little" android:id="@+id/txtSummary" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<Button android:text="Button" android:id="@+id/btnFriction" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
है मैं PreferenceActivity
Preference fric = (Preference)this.findPreference("friction");
View v = fric.getView(null, null);
SeekBar sbFriction = (SeekBar)v.findViewById(R.id.sbFriction);
sbFriction.setOnSeekBarChangeListener(this);
Button btnFric = (Button) v.findViewById(R.id.btnFriction);
btnFric.setOnClickListener(m_onClick);
लेकिन इन घटनाओं श्रोताओं में OnCreate में देखा गया हो सकता है, कि मैं निर्धारित किया है के लिए, निकाल दिया नहीं कर रहे हैं। मैं इन घटनाओं को कैसे पकड़ सकता हूं, उदाहरण के लिए - बटन से क्लिक करें। संपादित करें। नहीं, यह किसी भी अपवाद को आग नहीं लगा। यहाँ और अधिक विस्तृत कोड
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSeekBarChangeListener
{
private TextView m_txtSummary;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ListPreference difficulty = (ListPreference)this.findPreference("difficulty");
difficulty.setSummary(difficulty.getEntry());
difficulty.setOnPreferenceChangeListener(this);
Preference fric = (Preference)this.findPreference("friction");
View v = fric.getView(null, null);
SeekBar sbFriction = (SeekBar)v.findViewById(R.id.sbFriction);
sbFriction.setOnSeekBarChangeListener(this);
Button btnFric = (Button) v.findViewById(R.id.btnFriction);
btnFric.setOnClickListener(m_onClick);
m_txtSummary = (TextView)v.findViewById(R.id.txtSummary);
fric.setSummary(fric.toString());
fric.setOnPreferenceChangeListener(this);
CheckBoxPreference music = (CheckBoxPreference)this.findPreference("music");
music.setOnPreferenceChangeListener(this);
}
private OnClickListener m_onClick = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.getId();
}
};
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue instanceof Boolean)
return true;
preference.setSummary(newValue.toString());
return true;
}
@Override
public void onProgressChanged(SeekBar v, int nProgress, boolean arg2) {
// TODO Auto-generated method stub
m_txtSummary.append(" " + nProgress);
m_txtSummary.invalidate();
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
//notifyChanged();
}
}
कोई अपवाद या त्रुटियों निकाल दिया? मेरे लिए ऐसा लगता है कि यह काम करना चाहिए। BtnFric.setOnClickListener (नया OnClickListener() {@Override ...}) आज़माएं; – Vinay
नहीं, इसने किसी अपवाद को नहीं रोका। – hardsky
मुझे वरीयता से विरासत मिली, जैसा कि यहां दिया गया [लिंक] (http://stackoverflow.com/questions/5050272/android-seekbarpreference) – hardsky