Android:CursorAdapter、ContentResolver、startManagingCursor
程序员文章站
2022-03-10 14:48:32
...
public class MainActivity extends ListActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
ContentResolver cr = getContentResolver();//得到contentprovider对象
final Cursor c = cr.query(Phones.CONTENT_URI, null, null, null, null);//得到表的游标对象
startManagingCursor(c);
setListAdapter(new CursorAdapter(this,c)
{
@Override//找到行布局
public View newView(Context context, Cursor cursor, ViewGroup viewGroup)
{
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(android.R.layout.simple_list_item_2, null);
return layout;
}
@Override//获取和设置行布局控件
public void bindView(View view, Context context, Cursor cursor)
{
TextView tvName = (TextView) view.findViewById(android.R.id.text1);
TextView tvPhone = (TextView) view.findViewById(android.R.id.text2);
String name = c.getString(c.getColumnIndex("name"));
String phone = c.getString(c.getColumnIndex("number"));
tvName.setText(name);
tvPhone.setText(phone);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
转载于:https://blog.51cto.com/glblong/1216878
下一篇: java中equals的理解
推荐阅读
-
Android中ContentProvider和ContentResolver详解
-
android ContentResolver获取手机电话号码和短信内容
-
简单讲讲android 如何使用contentResolver
-
Android中ContentProvider和ContentResolver详解
-
android ContentResolver获取手机电话号码和短信内容
-
简单讲讲android 如何使用contentResolver
-
Android学习--ContentProvider&ContentResolver
-
Android课程——ContentProvider&ContentResolver
-
Android 中ContentProvider 和 ContentResolver使用入门
-
Android:CursorAdapter、ContentResolver、startManagingCursor