名单preferences没有任何单选按钮? [英] ListPreferences without any radio buttons?

查看:105
本文介绍了名单preferences没有任何单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个列表preference在我的preferenceActivity。

I want to create a ListPreference in my PreferenceActivity.

在列表preference被点击,我得到一个列表视图的对话框。在列表视图中的每一行都有一个文本框和一个单选按钮。

When a ListPreference is clicked, I get a dialog box with a listview. Each row in list view has a text field and a radio button.

我不想要这个单选按钮,也单击列表中的项目,我想火,打开浏览器的意图是什么?不知道如何去做?

I do not want this radio button and also on clicking list item, I want to fire an intent that opens browser? Any idea how to go about it?

如果我延长对话框preference那么如何处理onClicks?像onListClickListener是否行得通呢?

If i extend DialogPreference then how to handle onClicks? Like onListClickListener will work?

如果我向列表preference什么是我需要覆盖的功能?

If i extend ListPreference what are the functions i need to override?

推荐答案

这是可能的,当你正在定制preferences.When您只使用preference,它就像一个button.And以后你要实现任何你want.The以下示例仅显示了您的requirement.When单击preference,就说明没有单选按钮列表对话框。但我没有实现为存储要在共享preferences.If数据做到这一点,你必须实现你的own.I只是张贴一些code在这里。

This is possible when you are customizing preferences.When you are using only Preference ,it works like a button.And later you have to implement whatever you want.The Following example simply shows as your requirement.When you click preference,it shows list dialog without radio buttons .But i am not implemented to store the data in Shared preferences.If you want to do that,you have to implement your own.I just post some code here.

prefereces=findPreference("intent");
       // prefereces.setIntent(new Intent(Intent.ACTION_VIEW,Uri.parse("https://market.android.com/")));
  // prefereces.setIntent(new Intent(getApplicationContext(), DynamicPreference.class));

       prefereces.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            // TODO Auto-generated method stub

            createListPreferenceDialog();
            return true;
        }


    });


    }
    private void createListPreferenceDialog()
    {

        Dialog dialog;
        final CharSequence str[]={"Android","Black Berry","Symbian"};
        AlertDialog.Builder b=new AlertDialog.Builder(PreferenceActivities1Activity.this);
        b.setTitle("Mobile OS");

        b.setItems(str, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int position)
            {

                showToast("I am Clicked "+str[position]);
//              switch (position) 
//              {
//              case 0:
//                  showToast("I am Clicked "+str[position]);
//                  break;
//
//              default:
//                  break;
//              }

            }
        });

        dialog=b.create();
        dialog.show();

    }
    public void showToast(String msg)
    {
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }

这篇关于名单preferences没有任何单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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