android 如何从sqlite读取数据到spinner下拉中显示
1个回答
展开全部
这是我刚写的简单例子,从联系人里读取数据,填入spinner,希望有用~
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
public class temp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Cursor c = managedQuery(Data.CONTENT_URI,
new String[]{ Data._ID, Data.DATA1 },
Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'",
null,
null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_dropdown_item_1line,
c,
new String[]{ Data.DATA1 },
new int[]{ android.R.id.text1 });
Spinner s1 = (Spinner) findViewById(R.id.Spinner01);
s1.setAdapter(adapter);
}
}
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
public class temp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Cursor c = managedQuery(Data.CONTENT_URI,
new String[]{ Data._ID, Data.DATA1 },
Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'",
null,
null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_dropdown_item_1line,
c,
new String[]{ Data.DATA1 },
new int[]{ android.R.id.text1 });
Spinner s1 = (Spinner) findViewById(R.id.Spinner01);
s1.setAdapter(adapter);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询