我尝试使用db表的数据填充建议列表.但是我得到了StaleDataException.它会随机抛出,但总是在我将一个角色输入textview时.
这是我的代码:
CursorLoader扩展了Cristian的SimpleCursorLoader类
public class TagCursorLoader extends SimpleCursorLoader {
private String mSelection;
private TagDbLoader mDbLoader;
public TagCursorLoader(Context context, TagDbLoader dBLoader, String selection) {
super(context);
this.mDbLoader = dBLoader;
this.mSelection = selection;
}
@Override
public Cursor loadInBackground() {
return mDbLoader.fetchContainingString(mSelection);
}
}
Run Code Online (Sandbox Code Playgroud)
Loader回调:
public class TagCursorLoaderCallback implements LoaderCallbacks<Cursor>, CursorToStringConverter {
private Context mContext;
private TagDbLoader mdDbLoader;
private SimpleCursorAdapter mAdapter;
private String mSelection;
public TagCursorLoaderCallback(Context context, TagDbLoader dBLoader, SimpleCursorAdapter adapter) {
this.mContext = context;
this.mdDbLoader = dBLoader; …Run Code Online (Sandbox Code Playgroud) android simplecursoradapter android-cursor android-sqlite android-cursoradapter
我有以下代码:
public class Bar {}
public class FooBar {}
public class Foo {
public void method() {
new Bar() {
void otherMethod() { }
void barMethod() {
new FooBar() {
void fooBarMethod() {
Bar.this.otherMethod(); // not compiles
}
};
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
所以我有一个匿名内部类,其中有另一个匿名内部类.问题:有没有办法Bar从内部内部类访问外部内部类的方法FooBar?
我正在构建一个小型Forms应用程序,我刚刚启动它.但我有这个问题:如果我将一个控件放到窗体上,KeyDown事件不会触发.我知道KeyPreview属性,并将其设置为true.但这没有帮助... :(我也试图把焦点放在主要形式上,也没有成功.
有什么想法吗?
编辑:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
KeyDown += new KeyEventHandler(Form1_KeyDown);
this.KeyPreview = true;
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Left: MessageBox.Show("Left");
break;
case Keys.Right: MessageBox.Show("Right");
break;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个 repo,其中有一个子模块。
我可以轻松地从工作目录中获取子模块的当前哈希值:
cd submodule
git rev-list HEAD | head -n 1
Run Code Online (Sandbox Code Playgroud)
但是,我也对主 repo 以前版本的哈希感兴趣。如果我实际查看该版本,我可以得到它:
git checkout some_tag
cd submodule
git rev-list HEAD | head -n 1
Run Code Online (Sandbox Code Playgroud)
但是,我不能使用git checkout。有没有办法在不检查旧标签的情况下获得该哈希值?
我使用数据结构,并对这些数据结构进行了大量排序.这些数据结构保存指向对象的指针,而不是直接指向对象本身.现在我可以编写一个简单的比较函数或函数来告诉排序算法如何对指针进行排序:
struct Object_ptr_comparer {
bool operator()(const Object* first, const Object* second) {
return *first < *second;
}
};
Run Code Online (Sandbox Code Playgroud)
并使用例如std::sort:
Object_ptr_comparer comp;
std::sort(data_str.begin(), data_str.end(), comp);
Run Code Online (Sandbox Code Playgroud)
这个解决方案的唯一问题是我必须为任何类型的类编写额外的指针比较器函子.是的,我可以使用继承和多态来只写一些根类的比较器,但我不想这样做.有没有其他聪明的方法来做到这一点?
我有ListView,我有列表项的背景:

有没有办法shape在drawableXML中重新创建此背景?最外层的灰色不是项目背景的一部分,它实际上是ListView.
我写了这段代码片段来生成随机日期:
std::time_t curr_time = time(0);
std::time_t ten_years = 365 * 12 * 30 * 24 * 60;
std::time_t rand_date = curr_time - std::rand() % ten_years;
tm *ltm = std::localtime(&rand_date);
std::cout << ltm->tm_year + 1900 << " " << ltm->tm_mon + 1 << " " << ltm->tm_mday << std::endl;
Run Code Online (Sandbox Code Playgroud)
但是它总是给我当前的日期.我究竟做错了什么?
我有这个布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin" >
<LinearLayout
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我想要的是当用户输入的文本多于适合单行的文本时,EditText包装线,自动增加高度并在下一行显示不合适的文本.本EditText不应该是滚动的水平.
我读了很多与此相关的问题,但没有一个有帮助.目前EditText上面没有包装线,可以水平滚动.我在Android 4.2和4.4上测试过.
编辑:添加完整的布局.
EDIT2:
对不起,这是我的错.我在代码中以编程方式更改输入类型:
mEditText.setInputType(mInputTypes.get(question.getType()));
Run Code Online (Sandbox Code Playgroud)
所以使用这一行,我已经覆盖了xml的输入类型.我修改了代码,multiLine输入类型确实有效.
我正在尝试构建一个项目,但是当我尝试从命令行构建它时出现以下错误:
error: Could not find the AndroidManifest.xml file, going up from path [C:\Users\User\Documents\work
space\app\app\app\build\generated\source\apt\debug] found using dummy file []
(max atempts: file:///C:/Users/User/Documents/workspace/app/app/app/build/generated/source/apt/debug/dummy1449680140847.java)
Run Code Online (Sandbox Code Playgroud)
我的manifest.xml位于项目结构中的主要对象之下。这是我的gradle文件:
import com.android.builder.core.DefaultManifestParser
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.ponideapps.recetapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// This is important, it …Run Code Online (Sandbox Code Playgroud) 我正在使用gradle 3.0.0-alpha1在android studio 3.0预览版中使用Lombok。我的依存关系中有以下两个注释处理器:
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
annotationProcessor "org.projectlombok:lombok:1.16.16"
Run Code Online (Sandbox Code Playgroud)
现在,如果我在同一类中使用来自两个依赖项的注释,例如:
@Entity(tableName = "test")
@Getter
public final class TestEntity {...}
Run Code Online (Sandbox Code Playgroud)
它将产生一个错误,即:
error: Cannot find getter for field.
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除其中任何一个,它将可以正常工作。
有什么想法/解决方案吗?