通过匹配设置 Spinner 位置来获取字符串的 Cursor 位置
我正在获取呼叫者的自定义铃声 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论