本文介绍了如何输入过滤器应用到的EditText preferences?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想输入过滤器适用于我的EditText preferences ...

在我使用preferenceActivity我有这样的过滤器EditTexts:

  ET1 =(EditText上)findViewById(R.id.editText1);
            ET2 =(EditText上)findViewById(R.id.ETminsim);
            ET3 =(EditText上)findViewById(R.id.ETdelay);            et1.setText(Integer.toString(PlotView.playlist_size),EditText.BufferType.EDITABLE);            et2.setText(Integer.toString(conversorToInt(PlotView.min_sim)),EditText.BufferType.EDITABLE);
            et3.setText(Integer.toString(MusicService.getSeek()/ 1000),EditText.BufferType.EDITABLE);            et1.setFilters(新输入过滤器[] {新InputFilterMinMax(1,30)});
            et2.setFilters(新输入过滤器[] {新InputFilterMinMax(0,100)});
            et3.setFilters(新输入过滤器[] {新InputFilterMinMax(0,300)});

但我怎么能参考的EditText preference的EditTexts以设置这些过滤器?

我的新code:

 公共无效的onCreate(捆绑包){
                 super.onCreate(包);                 获得preferenceManager()setShared preferencesName(辛格尔顿preFS_NAME)。
                 加preferencesFromResource(R.xml preFS);                 // TODO设置输入过滤器
}


解决方案

有它主要是正确的。结合他的回答与他的回答塞巴斯蒂安的评论,你会得到

 的EditText editText1 =((EditText上preference)找到preference(preference_1_key))
                         .getEditText();
editText1.setFilters(新输入过滤器[] {新InputFilterMinMax(1,30)});

I want to apply InputFilter to my EditTextPreferences...

Before I used the PreferenceActivity I had EditTexts with Filters like that:

            et1 = (EditText) findViewById(R.id.editText1);
            et2 = (EditText) findViewById(R.id.ETminsim);
            et3 = (EditText) findViewById(R.id.ETdelay);

            et1.setText(Integer.toString(PlotView.playlist_size), EditText.BufferType.EDITABLE);

            et2.setText(Integer.toString(conversorToInt(PlotView.min_sim)), EditText.BufferType.EDITABLE);
            et3.setText(Integer.toString(MusicService.getSeek()/1000), EditText.BufferType.EDITABLE);

            et1.setFilters(new InputFilter[]{ new InputFilterMinMax(1, 30)});
            et2.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
            et3.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 300)});

But how can I reference to the EditTexts of the EditTextPreference in order to set these Filters?

My new Code:

public void onCreate(Bundle bundle) {
                 super.onCreate(bundle);

                 getPreferenceManager().setSharedPreferencesName(Singleton.PREFS_NAME);
                 addPreferencesFromResource(R.xml.prefs);

                 //TODO set InputFilter
}
解决方案

Konstantin had it mostly correct. Combine his answer with Sebastian's comment on his answer and you get

EditText editText1 = ((EditTextPreference) findPreference(preference_1_key))
                         .getEditText();
editText1.setFilters(new InputFilter[]{ new InputFilterMinMax(1, 30) });

这篇关于如何输入过滤器应用到的EditText preferences?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 14:10