在preference屏幕的Andr​​oid的EditText [英] android EditText in preference screen

查看:134
本文介绍了在preference屏幕的Andr​​oid的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以把一个EditText元素在preference屏?

Can I put an EditText element in a preference screen?

我想这样做,通过键入允许的大名单preference的快速搜索,但不希望保存搜索框的内容是什么?这是可能的,或者是标准布局控件不允许在preference屏幕。

I want to do this to allow fast searching of a large ListPreference by typing, but do not want to save the contents of the search box? Is this possible, or are standard layout controls not allowed on preference screens.

的目的是提供选择时区并将其保存为preference的手段。单独使用一个ListView prefernce是因为必须虽然滚动的时区数量巨大的不充分。因此,我想提供输入框的hypersearch类型,其中用户可以键入一个时区或部分缩小列表框中选择了。

The goal is to provide a means of selecting a time-zone and saving it as a preference. Using a ListViewPrefernce alone isn't sufficient because of the huge amount of time-zones that must be scrolled though. Hence, I would like to provide a "hypersearch" type of input box where the user can type a time-zone or part of one to narrow the list box selection down.

推荐答案

你可以做什么只是做一个标准的preference这将显示包含一个EditText一个对话框,并添加ontextchangelistener:

What you could do is just make a standard Preference which will show a dialog containing an EditText, and add an ontextchangelistener:

searchET.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub              
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub              
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });

和尽可能显示搜索结果,我不知道。我从来没有尝试过任何这之前明确,但看起来它会为你工作,你必须弄清楚什么$需要C $ C到执行搜索本身,但是这会增加初始功能。

and as far as showing the search results, I don't know. I've never tried any of this specifically before, but it seems like it would work for you, and you'd have to figure out whatever code is needed to perform the search itself, but this would add the initial functionality.

编辑:
通过标准preference,我指的是在XML:

By standard Preference, I mean in the XML:

<Preference
    android:title="Time Zone"
    android:summary="Choose your time zone"
    android:key="timeZone"/>

而在你的preferenceActivity添加以下内容:

And in your PreferenceActivity add the following:

Preference timeZone = (Preference)findPreference("timeZone");
     timeZone.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                showDialog(1);
                return false;
            }
        });



@Override
    protected Dialog onCreateDialog(int id) {

    switch (id) {       

    case 1: 
        final EditText searchET = new EditText(this);
//do the searchET.addTextChangedListener here
                 return new AlertDialog.Builder(this)
.setTitle("Choose Time Zone")
.setView(showAppString)
.setPositiveButton(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
    //save the time zone to sharedPreferences
SharedPreferences pref = PreferenceManager.getDefaultSharedPreference(this);
SharedPreferences.Editor editor = pref.edit();
editor.putString("TIME_ZONE", TZ.toString());

}//closes the onClick
})//closes the onclicklistener
.show();
}//closes the switch

}//closes the oncreatedialog

不过,我觉得你其实可以只使用一个EditText preference然后addTextChangedListner到的EditText preference,因为我认为它继承一切从EditTexts。我不是高建国,虽然。

Though, I think you could actually just use an EditTextPreference and then addTextChangedListner to the EditTextPreference, since I THINK it inherits everything from EditTexts. I'm not postitive, though.

这篇关于在preference屏幕的Andr​​oid的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆