草庐IT

gravity_value_t

全部标签

Kotlin 数据类 : how to read the value of property if I don't know its name at compile time?

如果属性名称仅在运行时已知,我如何读取Kotlin数据类实例中的属性值? 最佳答案 这是一个从给定属性名称的类的实例中读取属性的函数(如果未找到属性则抛出异常,但您可以更改该行为):importkotlin.reflect.KProperty1importkotlin.reflect.full.memberProperties@Suppress("UNCHECKED_CAST")funreadInstanceProperty(instance:Any,propertyName:String):R{valproperty=instan

spring - 如何在 kotlin 中将 @Autowired 或 @Value 等 Spring 注释用于原始类型?

使用spring注释Autowiring非基元,例如@AutowiredlateinitvarmetaDataService:MetaDataService有效。但这不起作用:@Value("\${cacheTimeSeconds}")lateinitvarcacheTimeSeconds:Int出现错误:lateinitmodifierisnotallowedforprimitivetypes.如何将原始属性Autowiring到kotlin类中? 最佳答案 你也可以在构造函数中使用@Value注解:classTest(@Valu

android - 未知属性android :layout_width, layout_height,id,gravity,layout_gravity,padding

在所有android标签上出现未知属性错误。在布局XML中,自动建议未显示所有属性(如layout_width、layout_height、orientation、orientation和所有其他android属性。)这是一个快照我为解决这个问题所做的事情。清理构建和重建已删除.idea文件无效的缓存/重新启动..选项打开省电模式。SDk是最新的。在应用级网格中applyplugin:'com.android.application'android{compileSdkVersion23buildToolsVersion"23.0.2"defaultConfig{application

android - IllegalArgumentException : the bind value at index 1 is null

有人知道这是什么意思吗?12-3120:55:45.861:ERROR/AndroidRuntime(12478):Causedby:java.lang.IllegalArgumentException:thebindvalueatindex1isnull12-3120:55:45.861:ERROR/AndroidRuntime(12478):atandroid.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:234)12-3120:55:45.861:ERROR/AndroidRuntime(12478):at

Android 偏好设置 : How to load the default values when the user hasn't used the preferences-screen?

我正在使用PreferenceActivity让用户设置一些值。我正在用定义的首选项向它提供xml文件。我已经为他们设置了所有的android:defaultValue=""。当我启动我的应用程序时,我需要首选项,或者如果尚未手动设置它们,我需要默认值:SharedPreferencesprefs=PreferenceManager.getDefaultSharedPreferences(this);booleanvalue=prefs.getBoolean("key"),false);但是,当android:defaultValue="true"我仍然得到false。因此,看起来XM

android - 如何设置android :gravity to TextView from Java side in Android

我可以在textview的xml中使用android:gravity="bottom|center_horizo​​ntal"来获得我想要的结果,但我需要以编程方式执行此操作。如果在relativelayout中很重要,我的textview在tablerow内。我试过了:LayoutParamslayoutParams=newTableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);labelTV.setLayou

android - 从源代码的 res/values/dimension.xml 加载维度值

我想按原样加载该值。我有两个dimension.xml文件,一个在/res/values/dimension.xml中,另一个在/res/values-sw360dp/dimension.xml。从源代码我想做类似的事情getResources().getDimension(R.dimen.tutorial_cross_marginTop);这可行,但我得到的值乘以屏幕密度因子(hdpi为1.5,xhdpi为2.0等)。我也试过了getResources().getString(R.dimen.tutorial_cross_marginTop);这原则上可行,但我得到一个以“dip”结

c# - ReadBsonType 只能在 State 为 Type 时调用,不能在 State 为 Value 时调用

我们需要将一些字符串格式的数据移动到枚举中,并且由于现有数据与我们希望枚举的外观不符,我正在使用自定义序列化器(在MongoDB中)。我的代码看起来像这样:publicoverrideMyEnumDeserialize(BsonDeserializationContextcontext,BsonDeserializationArgsargs){if(context.Reader.CurrentBsonType==MongoDB.Bson.BsonType.Null)returnMyEnum.Unknown;returnParseMyEnum(context.Reader.ReadStr

c++ - 新的 C++ Mongo 驱动程序 : how to see type and how to get string value

我有两个问题在教程中找不到答案。我得到一个文档,然后是文档中的一个元素,如下所示:bsoncxx::document::elemente=doc["id"];if(!e||e.type()!=bsoncxx::type::k_int32)returnERROR;intid=e.get_int32();有没有办法获取该类型的字符串值以用于调试目的?喜欢:std::cout(这不起作用)第二个问题是如何将utf8类型的值转换成std::string。这不起作用:e=doc["name"];if(!e||e.type()!=bsoncxx::type::k_utf8)returnERROR;

Java MongoDB 获取子文档的值(value)

我正在尝试从子文档中获取键的值,但我似乎无法弄清楚如何使用BasicDBObject.get()函数,因为键嵌入了两层深。这是文档的结构File{name:file_1report:{name:report_1,group:RnD}}基本上一个文件有多个报告,我需要检索给定文件中所有报告的名称。我能够做到BasicDBObject.get("name")并且我可以获得值“file_1”,但是我该如何做这样的事情BasicDBObject.get("report.name")?我试过了,但没有用。 最佳答案 您应该首先获取“报告”对象