通过匹配设置 Spinner 位置来获取字符串的 Cursor 位置

发布于 2024-12-22 11:29:33 字数 1743 浏览 3 评论 0原文

我正在获取呼叫者的自定义铃声 ID,基本上我想做一个 setSelection();到我的微调器与该铃声,但我不知道如何匹配位置。

我尝试的是匹配字符串“铃声名称”,以从光标找到它在微调器中的位置。我以正确的方式处理这件事吗?或者是否有更简单的方法将铃声 ie:content://media/internal/audio/media/72 与微调器中的位置匹配?

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        mRingtoneManager2 = new RingtoneManager(this); //adds ringtonemanager
        mRingtoneManager2.setType(RingtoneManager.TYPE_RINGTONE); //sets the type to ringtones
        mRingtoneManager2.setIncludeDrm(true); //get list of ringtones to include DRM

        mCursor2 = mRingtoneManager2.getCursor(); //appends my cursor to the ringtonemanager

        startManagingCursor(mCursor2); //starts the cursor query

        String[] from = {mCursor2.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX)}; // get the list items for the listadapter could be TITLE or URI

        int[] to = {android.R.id.text1}; //sets the items from above string to listview
        // create simple cursor adapter
        SimpleCursorAdapter adapter =
          new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mCursor2, from, to );
        adapter.setDropDownViewResource( android.R.layout.simple_spinner_item);
        // get reference to our spinner
        s = (Spinner) findViewById( R.id.spinner1);
        s.setAdapter(adapter);
                getValue(mCursor2);
        s.setSelection(posid);
        s.setOnItemSelectedListener(this);

            }

    public String getValue(Cursor cursor) {
            String posid = "Loopy Lounge";
            while (cursor.moveToNext()) {
                posid = cursor.getString(0);
            }
            return;
        }

I'm getting the custom ringtone ID by caller and basically I want to do a setSelection(); to my spinner with that ringtone but I can't figure out how to match positions..

What I've tried is to match a string "Ringtone Name" to find it's position in a Spinner from it's cursor. Am I going about it the right way? Or is there an easier way to match ringtone ie:content://media/internal/audio/media/72 to the position in the spinner?

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        mRingtoneManager2 = new RingtoneManager(this); //adds ringtonemanager
        mRingtoneManager2.setType(RingtoneManager.TYPE_RINGTONE); //sets the type to ringtones
        mRingtoneManager2.setIncludeDrm(true); //get list of ringtones to include DRM

        mCursor2 = mRingtoneManager2.getCursor(); //appends my cursor to the ringtonemanager

        startManagingCursor(mCursor2); //starts the cursor query

        String[] from = {mCursor2.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX)}; // get the list items for the listadapter could be TITLE or URI

        int[] to = {android.R.id.text1}; //sets the items from above string to listview
        // create simple cursor adapter
        SimpleCursorAdapter adapter =
          new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mCursor2, from, to );
        adapter.setDropDownViewResource( android.R.layout.simple_spinner_item);
        // get reference to our spinner
        s = (Spinner) findViewById( R.id.spinner1);
        s.setAdapter(adapter);
                getValue(mCursor2);
        s.setSelection(posid);
        s.setOnItemSelectedListener(this);

            }

    public String getValue(Cursor cursor) {
            String posid = "Loopy Lounge";
            while (cursor.moveToNext()) {
                posid = cursor.getString(0);
            }
            return;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文