我有一个自定义ContentProvider管理SQLite数据库的访问.要在a中加载数据库表的内容ListFragment,我使用LoaderManagerwith a CursorLoader和a CursorAdapter:
public class MyListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
// ...
CursorAdapter mAdapter;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new CursorAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
getLoaderManager().initLoader(LOADER_ID, null, this);
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new CursorLoader(getActivity(), CONTENT_URI, PROJECTION, null, null, null);
}
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
mAdapter.swapCursor(c);
}
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
}
Run Code Online (Sandbox Code Playgroud)
SQLite数据库由后台任务更新,后台任务从Web服务获取大量项目,并通过ContentProvider批处理操作将这些项目插入数据库(ContentResolver#applyBatch()). …
sqlite android cursor android-contentprovider android-cursoradapter
我有一个ContentProvider允许LEFT OUTER JOIN在SQLite数据库上进行查询的Android .
让我们假设在数据库中我有3个表Users,Articles和Comments.该ContentProvider是类似以下内容:
public class SampleContentProvider extends ContentProvider {
private static final UriMatcher sUriMatcher;
public static final String AUTHORITY = "com.sample.contentprovider";
private static final int USERS_TABLE = 1;
private static final int USERS_TABLE_ID = 2;
private static final int ARTICLES_TABLE = 3;
private static final int ARTICLES_TABLE_ID = 4;
private static final int COMMENTS_TABLE = 5;
private static final int COMMENTS_TABLE_ID = 6;
private static final …Run Code Online (Sandbox Code Playgroud) 我有一个自定义Android ContentProvider,它存储和检索SQLite数据库中的数据.
假设其中一个数据库表有一_ID列和一NAME列,内容如下:
|==========|==========|
| _ID | NAME |
|==========|==========|
| 1 | d1 |
| 2 | d2 |
| 3 | d3 |
| 4 | d4 |
|==========|==========|
Run Code Online (Sandbox Code Playgroud)
此SQLite DB与远程数据库保持同步,并通过网络定期获取新数据.表中可能的操作如下:
现在让我们假设所有可能的操作同时发生,并且在从远程服务器获取一些最新数据之后,该表的新内容必须设置如下:
|==========|==========|
| _ID | NAME |
|==========|==========|
| 1 | d7 |
| 3 | d3 |
| 4 | d6 |
| 5 | d5 |
|==========|==========|
Run Code Online (Sandbox Code Playgroud)
可以有两种不同的方法来做到这一点:
DELETESQL命令删除整个表,然后添加从服务器接收的所有行在Android上,我目前正在使用批处理操作实现第二种方法,以最大限度地提高性能: …
是否可以进行AsyncTask.doInBackground同步 - 或以另一种方式实现相同的结果?
class SynchronizedTask extends AsyncTask {
@Override
protected synchronized Integer doInBackground(Object... params) {
// do something that needs to be completed
// before another doInBackground can be called
}
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,任何AsyncTask.execute()可以在前一个完成之前启动,但我只需要doInBackground在上一个任务完成后执行代码.
编辑:正确指出,同步仅适用于同一对象实例.遗憾的是,无法在同一对象实例上创建AsyncTask和调用execute()多次,如AsyncTask 文档的"线程规则"部分所述.
解决方案是使用自定义Executor来序列化任务,或者,如果您使用API 11或更高版本,AsyncTask.executeOnExecutor()则按照以下注释中的建议使用.
我发布了一个答案,显示了一个SerialExecutor可用于对将按顺序执行的任务进行排队的实现.
我需要一个PHP函数,可以断言两个数组是相同的,而忽略指定键集的值(只有值,键必须匹配).
实际上,数组必须具有相同的结构,但可以忽略某些值.
例如,考虑以下两个数组:
Array
(
[0] => Array
(
[id] => 0
[title] => Book1 Title
[creationDate] => 2013-01-13 17:01:07
[pageCount] => 0
)
)
Array
(
[0] => Array
(
[id] => 1
[title] => Book1 Title
[creationDate] => 2013-01-13 17:01:07
[pageCount] => 0
)
)
Run Code Online (Sandbox Code Playgroud)
如果我们忽略键的值,它们就是一样的id.
我还想考虑嵌套数组的可能性:
Array
(
[0] => Array
(
[id] => 0
[title] => Book1 Title
[creationDate] => 2013-01-13 17:01:07
[pageCount] => 0
)
[1] => Array
(
[id] => 0
[title] …Run Code Online (Sandbox Code Playgroud) 我需要使用分页读取 MS SQL 数据库表的内容,即获取第一页的 N 行,然后获取第二页的 N 行,依此类推。
如果数据库的内容在分页期间发生显着变化,则可以使用简单的分页查询,例如:
SELECT *
FROM (SELECT a.*,
ROW_NUMBER() OVER (ORDER BY id) AS rnum
FROM articles a)
WHERE rnum <= 10
AND rnum >= 6;
Run Code Online (Sandbox Code Playgroud)
可能无法可靠工作。插入的行可以被跳过或可能导致后续行重复,而删除的行可能导致后续行被跳过。
我可以通过执行以下任一操作来避免此类问题:
我有点喜欢第三种解决方案,但我发现当排序列中存在重复值时很难实现。
例如,假设我有一个按评级降序排序的文章列表。如果评分相同,则按ID升序排序(ID唯一):
ID RATING
9 34
3 32
6 32
8 32
12 32
1 25
2 23
Run Code Online (Sandbox Code Playgroud)
现在,我想要包含 3 篇文章的页面,这意味着第一页将包含文章 9、3 和 6。这是通过查询排序列表中的前 3 篇文章来完成的。
现在,我想从第 8 篇文章中恢复接下来的 3 篇文章,并使用文章 ID 作为恢复位置的标记。
如果我告诉数据库采用第 8 篇文章的信誉,而不是采用信誉度低于此的 3 …
这个重复的动画代码会减慢我的系统吗?:
@-webkit-keyframes animate {-webkit-animation-iteration-count:infinite;...}
Run Code Online (Sandbox Code Playgroud)
所有CSS3属性都是CPU密集型的吗?
谢谢.
我想将图像包装成一个html DIV,因为我希望这个窗口的大小完全可扩展,我想设置DIV百分比的宽度,如下所示:
HTML
<div id="wrapper">
<img src="http://openclipart.org/people/netalloy/rally-car.svg" />
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
#wrapper {
position: absolute;
width: 50%;
}
#wrapper img {
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
图像应确定其容器的高度.这是因为图像宽度设置为100%并且相应地计算图像高度以保持正确的宽高比.
结果在jsfiddle上可见:http://jsfiddle.net/lorenzopolidori/5BN4g/15/
我的问题是:
DIV比内部图像高5px?令人惊讶的是,这种情况发生在Chrome(21.0.1180.89),Firefox(15.0.1)和IE8中,而IE7正确呈现,与图像的高度相匹配DIV.
我正在使用此代码将图像存储到相机操作完成时的隔离存储中.
void camera_Completed(object sender, PhotoResult e)
{
BitmapImage objImage = new BitmapImage();
//objImage.SetSource(e.ChosenPhoto);
//Own_Image.Source = objImage;
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
fnam = e.OriginalFileName.Substring(93);
MessageBox.Show(fnam);
if (isolatedStorage.FileExists(fnam))
isolatedStorage.DeleteFile(fnam);
IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(fnam);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.ChosenPhoto);
WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 100, 100);
MessageBox.Show("File Created");
fileStream.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想从隔离存储中取出图像并将其显示在我的图像控件中.
可能吗?
使用以下代码可以使用动画更改活动:
Bundle animation = ActivityOptions.makeCustomAnimation(App.getContext(), R.anim.enter_from_right, R.anim.exit_to_left).toBundle();
startActivity(intent, animation);
Run Code Online (Sandbox Code Playgroud)
对于片段,您可以在FragmentTransaction上执行类似的操作:
// ...
transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left);
// ...
Run Code Online (Sandbox Code Playgroud)
这有效!但是我想在按下时弹出一个动画(从后台弹出).对于片段,您只需添加2个动画资源(popEnter和popExit):
transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
Run Code Online (Sandbox Code Playgroud)
如何为活动创建相同的"背景动画"?
我有以下(简化)数据库结构:
表 book
id
title
Run Code Online (Sandbox Code Playgroud)
表 page
id
bookId
number
Run Code Online (Sandbox Code Playgroud)
表 figure
id
pageId
Run Code Online (Sandbox Code Playgroud)
page.bookId并且figure.pageId是指向主键外键book.id和page.id分别.
一本书没有页面,页面也没有数字.
对于指定的书籍ID,使用单个 sql查询,我想要检索
结果的示例JSON表示如下:
{
"id": 34,
"title": "The title"
"pages": [
{
"id": "44",
"number": 1
"figureCount": 2
},
{
"id": "45",
"number": 2
"figureCount": 5
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
这可能与Propel 1.6和结果SQL查询应该是什么?
我使用MySql 5.0.
编辑:这是我的(简化)Propel schema.xml:
<table name="book" phpName="Book">
<column name="id" type="bigint" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" size="512" required="true" />
</table> …Run Code Online (Sandbox Code Playgroud) 有什么区别:
public class Worker
{
public static void Execute()
{
ExecuteInBackgroundThread().Wait();
}
private static Task ExecuteInBackgroundThread()
{
return Task.Run(() =>
{
// do some long running operation
});
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class Worker
{
public static void Execute()
{
ExecuteInBackgroundThread().Wait();
}
private static async Task ExecuteInBackgroundThread()
{
await Task.Run(() =>
{
// do some long running operation
});
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到Worker.Execute()从UI线程调用我的Windows Phone应用程序的第二个版本被卡住了.
相反,使用第一个版本似乎一切正常.
ExecuteInBackgroundThread实际返回的第二个版本是否Task<T>可以等待?但如果情况并非如此,编译器是否应该提出错误说我们没有返回任何内容?
android ×4
sql ×3
sqlite ×3
css ×2
cursor ×2
join ×2
arrays ×1
async-await ×1
c# ×1
css3 ×1
database ×1
html ×1
image ×1
mysql ×1
navigation ×1
pagination ×1
php ×1
phpunit ×1
propel ×1
sql-server ×1