我有一个访问我的数据库的内容提供程序,如果你需要处理记录集,这很好,但我需要一个方法来返回一个表示表中记录数的整数
该方法看起来像这样
public long getRecordCount(String TableName) {
SQLiteDatabase mDatabase = mOpenHelper.getReadableDatabase();
String sql = "SELECT COUNT(*) FROM " + TableName;
SQLiteStatement statement = mDatabase.compileStatement(sql);
long count = statement.simpleQueryForLong();
return count;
}
Run Code Online (Sandbox Code Playgroud)
但我无法在内容提供商中找到任何使用此方法(或任何其他不返回游标的方法),那么放置此方法的最佳位置以及如何调用它?
显然,我可以选择使用托管查询选择所有记录并使用cursor.count结果,这是一个非常糟糕的选择,但这是处理这个特定需求的一种非常低效的方法
谢谢
如何确保共享首选项菜单使用 UTF8?我有一个 android 首选项菜单,允许用户设置他们的名字等。
我需要知道如何将共享首选项中存储的数据转换为 UTF8 格式
首选项菜单使用 utf8 编码以 xml 格式布置在 res/xml 文件夹中名为 settings 的文件中,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="@string/name_key"
android:title="@string/hof_name_title"
android:summary="@string/hof_name_summary"
android:defaultValue="Anonymous" />
<CheckBoxPreference
android:key="@string/new_game_preference_key"
android:title="@string/new_game_preference_title"
android:summary="@string/new_game_preference_summary"
android:defaultValue="false" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
处理这个问题的类是
public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
@Override
protected void onPause() {
super.onPause();
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
protected void onResume() {
super.onResume();
// Set up …Run Code Online (Sandbox Code Playgroud) 在最近关于Meteor的Railscast之后,我的兴趣被激发了,特别是因为我正在为我的Rails应用程序实现实时事件提要.
在我看来,Meteor是我的要求的完美解决方案,但我有点陷入第一关.
我的要求是能够从我的主站点(Rails应用程序)将数据发布到Meteor服务器,并将生成的meteor客户端网页嵌入到我的主应用程序中.
那么我如何将数据发送到Meteor服务器并让Meteor客户端自动获取数据呢?
关于这个最佳方法的任何想法都赞赏.我想我正在寻找一个接受来自外部数据源的数据的Meteor api
更新 也许我需要编写一个DDP客户端来使用Rails?
我需要知道如何测试这个控制器动作
def create_mobile
if mobile_user = MobileUser.authenticate(params[:email], params[:password])
session[:mobile_user_id] = mobile_user.id
respond_to do |format|
format.json { head :ok }
end
else
respond_to do |format|
format.json { head :unauthorised }
end
end
end
Run Code Online (Sandbox Code Playgroud)
该路由是对sessions/create_mobile的发布请求,您可以看到该操作仅响应json
我当前的控制器规格看起来像这样
describe SessionsController, "Logging in" do
before(:each) do
@mobile_user = FactoryGirl.create(:valid_mobile_user)
end
it "Should log in mobile user" do
@request.env["HTTP_ACCEPT"] = "application/json"
post :create_mobile, {:password => @mobile_user.password, :email => @mobile_user.email}
response.should be_success
end
it "should fail log in mobile user" do
@request.env["HTTP_ACCEPT"] = "application/json"
post :create_mobile, {:password …Run Code Online (Sandbox Code Playgroud) 如果我打电话
Intent intent = new Intent(ReadingActivity.this, AdService.class);
startService(intent);
Run Code Online (Sandbox Code Playgroud)
从类的onCreate方法中MyActivity,我如何MyActivity.this从类的onHandleIntent()方法内部访问IntentService
@Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
((BookLib) getApplication()).createAd(I need to pass the calling activities context here);
}
Run Code Online (Sandbox Code Playgroud) 我刚刚使用在我的主题中应用了黑色背景图像
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@drawable/background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在我希望将我的文本视图的颜色更改为白色,以便它们在深色背景下可见
我认为为 TextView 设置 android:textColor 会像这样
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@drawable/background</item>
<item name="android:textViewStyle">@style/Ff1TextViewStyle</item>
</style>
<style name="Ff1SpinnerViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">@color/sysWhite</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但令我沮丧的是,这完全填满了各种各样的东西,比如微调文本和微调下拉文本、ActionBar 下拉菜单,通过将文本更改为白色背景上的白色,所有这些我之前都非常满意,而且我确定其他控件我尚未使用或尚未发现的内容很可能以白色文本结束。
我发现很难相信 android 主题如此混乱,以至于我无法自信地设置 TextView widgtes 的文本颜色而不影响我只能假设是 TextView 小部件的子部件的小部件,所以我认为它必须只是我缺乏知识是罪魁祸首,我希望并寻求对必须是共同要求的启示。
任何帮助表示赞赏。
在Rails 3.2应用程序(Ruby 1.9.2)中,我收到以下错误
在mobile_users#update中发生了PGError:
不完整的多字节字符
这些是Postgres错误我在开发和测试模式下测试时遇到类似的SQLIte错误
导致此错误的参数是(故意省略auth令牌)
* Parameters: {"mobile_user"=>{"quiz_id"=>"1", "auth"=>"xxx", "name"=>"Joaqu\xEDn"}, "action"=>"update", "controller"=>"mobile_users", "id"=>"1", "format"=>"mobile"}
Run Code Online (Sandbox Code Playgroud)
这是作为JSON HTTP Put请求进行的,处理此问题的更新操作如下所示
# PUT /mobile_users/1
# PUT /mobile_users/1.xml
def update
@mobile_user = current_mobile_user
@mobile_user.attributes = params[:mobile_user]
respond_to do |format|
if @mobile_user.save
format.html { redirect_to(@mobile_user, :notice => 'Mobile user was successfully updated.') }
format.json { head :ok }
format.mobile { head :ok }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @mobile_user.errors, :status => …Run Code Online (Sandbox Code Playgroud) 我(尝试)在rackspace上设置一个ubuntu 11.04服务器来运行带有nginx和unicorn的rails 3.2应用程序.我找到了这个很棒的博客http://techbot.me/2010/08/deployment-recipes-deploying-monitoring-and-securing-your-rails-application-to-a-clean-ubuntu-10-04-install-using -nginx-and-unicorn /它帮助我大规模地解决了mysql设置问题,我认为除了错误的网关错误外,我已经完成了一切
nginx错误日志显示
2012/02/25 14:38:34 [crit] 29139#0: *1 connect() to unix:/tmp/mobile.socket failed (2: No such file or directory) while connecting to upstream, client: xx.xx.xxx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/mobile.socket:/", host: xx.xx.xxx.xx
Run Code Online (Sandbox Code Playgroud)
(我已经x了域名)
我想这可能是一个用户权限的事情,但文件实际上并不存在,我不知道应该如何创建它.我不愿意手动创建它,因为我觉得这样做会修复症状而不是修复原因
还应该注意,我在服务器上创建的用户有sudo权限,需要使用sudo启动nginx,不确定这是否正确?关于我应该寻找什么来解决这个问题的任何指示都非常感谢.为了完整性,我的配置文件看起来像/etc/init.dunicorn
#! /bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web …Run Code Online (Sandbox Code Playgroud) 我有一个使用滚动视图的布局.滚动视图中文本的第一部分在模拟器中被切断,在HTC手机上,滚动视图滚动超过文本的末尾,需要大量滚动才能返回文本.
Eclipse抱怨说"这个ScrollView布局或其LinearLayout父版本是无用的",我怀疑这条消息是我的困境的主要罪魁祸首,但很高兴能够得到纠正
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Container"
android:id="@+id/about">
<ScrollView style="@style/Content">
<TextView style="@style/Content"
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text" />
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
风格
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme">
<item name="android:textColor">@color/txtColor</item>
</style>
<style name="ApplicationTheme" parent="android:Theme">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:colorBackground">@color/mnuColor</item>
<item name="android:textColor">@color/txtColor</item>
</style>
<style name="Container" parent="ApplicationTheme">
<item name="android:textColor">@color/txtColor</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:colorBackground">@color/mnuColor</item>
</style>
<style name="Webview" parent="Container">
<item name="android:background">@drawable/web_background_image</item>
<item name="android:windowBackground">@drawable/background_image</item>
<item name="android:colorBackground">@color/mnuColor</item>
</style>
<style name="MyPlaceDialog" parent="@android:style/Theme.Dialog">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:orientation">vertical</item>
<item name="android:stretchColumns">*</item>
</style>
<style name="Content">
<item …Run Code Online (Sandbox Code Playgroud) Rails 3.x before_validation(:on => :create) do不起作用.任何其他想法赞赏
如果有人能够展示在 Rails 6 或 Rails 7 Alpha 2 引擎中使用 jquery ui 所需的确切步骤,我将不胜感激。我无法让 importmap-rails 在 Rails 7 引擎中工作,也无法让 webpacker 在 Rails 6 引擎或 Rails 7 alpha 2 引擎中工作。给定一个名为 custom_page 的引擎,使用生成
rails plugin new custom_page --mountable --full
Run Code Online (Sandbox Code Playgroud)
我将 jquery-ui-rails 作为依赖项包含在 gemspec 中。
spec.add_dependency 'jquery-ui-rails'
Run Code Online (Sandbox Code Playgroud)
也许这应该是一个runtime_dependency?完整的依赖项列表是
spec.add_dependency "rails", "~> 7.0.0.alpha2"
spec.add_dependency 'new_ckeditor'
spec.add_dependency 'ancestry'
spec.add_dependency 'friendly_id', '>= 5.4.0'
spec.add_dependency 'pg_search'
spec.add_dependency 'carrierwave', '~> 2.0'
spec.add_dependency 'carrierwave-imageoptimizer'
spec.add_dependency 'sassc-rails', '~> 2.0.0'
spec.add_dependency 'pg', '~> 1.1'
spec.add_dependency 'jquery-rails'
spec.add_dependency 'jquery-ui-rails'
spec.add_development_dependency "puma"
#Testing Gems
spec.add_development_dependency …Run Code Online (Sandbox Code Playgroud) jquery-ui ruby-on-rails rails-engines ruby-on-rails-6 ruby-on-rails-7
在 Rails 6.0.3.1 中,有没有办法在不使用诸如安全标头 gem 之类的 gem 的情况下本机设置 Rails 会话 cookie 相同的站点属性?