Android之——ContentProvider操作XML

时间:2022-12-17 09:25:48
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47682559

不多说,不废话,直接上代码,大家一看都懂得

/**
* ContentProvider操作XML文件的封装示例方法
* @author liuyazhuang
*/
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SharedPreferences sp= getContext().getSharedPreferences("pim_preferences", Context.MODE_PRIVATE);
String[] columns = new String[] { "_id", "url", "target" };
MatrixCursor stringCursor = new MatrixCursor(columns);
String row[] = new String[3];
row[0] = "1";
row[1] = sp.getString("url", "");
row[2] = sp.getString("target", "");
stringCursor.addRow(row);
return stringCursor;
}