使RelativeLayout可检查(Make RelativeLayout checkable)
我尝试使用带有
TextView
和FrameLayout
RelativeLayout
编写我自己的CheckBox
(里面有选择器)。我有
setDuplicateParentStateEnabled(true)
,它从父级检查状态,但为什么使RelativeLayout
检查我不知道。public class MyCheckbox extends RelativeLayout implements OnClickListener, Checkable { private static final int ID_CHECKBOX = -1234411; private static final int ID_TEXTVIEW = -1234412; private static final int ID_PARENT = -1234413; private TextView textView; private FrameLayout checkBox; private boolean isChecked; public MyCheckbox(Context context) { this(context, null); } public MyCheckbox(Context context, AttributeSet attrs) { super(context, attrs); LayoutParams lp; setId(ID_PARENT); setOnClickListener(this); // checkBox checkBox = new FrameLayout(context); checkBox.setId(ID_CHECKBOX); checkBox.setDuplicateParentStateEnabled(true); // textView textView = new TextView(context); textView.setId(ID_TEXTVIEW); textView.setOnClickListener(this); boolean checkboxToRight = false; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaptrixCheckbox); for (int i = 0; i < a.getIndexCount(); i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.MyCheckbox_checkboxToRight: checkboxToRight = a.getBoolean(attr, false); break; case R.styleable.MyCheckbox_checkMark: checkBox.setBackgroundDrawable(a.getDrawable(attr)); break; case R.styleable.MyCheckbox_text: textView.setText(a.getText(attr)); break; } } a.recycle(); if (checkboxToRight) { lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(ALIGN_PARENT_RIGHT); lp.addRule(CENTER_VERTICAL); lp.setMargins(margins, 0, margins, 0); addView(checkBox, lp); lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.addRule(LEFT_OF, ID_CHECKBOX); addView(textView, lp); } else { lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.setMargins(margins, 0, margins, 0); addView(checkBox, lp); lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.addRule(RIGHT_OF, ID_CHECKBOX); addView(textView, lp); } refreshDrawableState(); } @Override public void onClick(View v) { int id = v.getId(); if (id == ID_PARENT || id == ID_TEXTVIEW) toggle(); } public boolean isChecked() { return isChecked; } public void setChecked(boolean chacked) { isChecked = chacked; refreshDrawableState(); } @Override public void toggle() { isChecked = !isChecked; refreshDrawableState(); } }
I try to write my own
CheckBox
usingRelativeLayout
withTextView
andFrameLayout
(with selector on background) inside.I have
setDuplicateParentStateEnabled(true)
forFrameLayout
that it take checkable status from parent, but why makeRelativeLayout
checkable I don't know.public class MyCheckbox extends RelativeLayout implements OnClickListener, Checkable { private static final int ID_CHECKBOX = -1234411; private static final int ID_TEXTVIEW = -1234412; private static final int ID_PARENT = -1234413; private TextView textView; private FrameLayout checkBox; private boolean isChecked; public MyCheckbox(Context context) { this(context, null); } public MyCheckbox(Context context, AttributeSet attrs) { super(context, attrs); LayoutParams lp; setId(ID_PARENT); setOnClickListener(this); // checkBox checkBox = new FrameLayout(context); checkBox.setId(ID_CHECKBOX); checkBox.setDuplicateParentStateEnabled(true); // textView textView = new TextView(context); textView.setId(ID_TEXTVIEW); textView.setOnClickListener(this); boolean checkboxToRight = false; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaptrixCheckbox); for (int i = 0; i < a.getIndexCount(); i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.MyCheckbox_checkboxToRight: checkboxToRight = a.getBoolean(attr, false); break; case R.styleable.MyCheckbox_checkMark: checkBox.setBackgroundDrawable(a.getDrawable(attr)); break; case R.styleable.MyCheckbox_text: textView.setText(a.getText(attr)); break; } } a.recycle(); if (checkboxToRight) { lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(ALIGN_PARENT_RIGHT); lp.addRule(CENTER_VERTICAL); lp.setMargins(margins, 0, margins, 0); addView(checkBox, lp); lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.addRule(LEFT_OF, ID_CHECKBOX); addView(textView, lp); } else { lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.setMargins(margins, 0, margins, 0); addView(checkBox, lp); lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.addRule(CENTER_VERTICAL); lp.addRule(RIGHT_OF, ID_CHECKBOX); addView(textView, lp); } refreshDrawableState(); } @Override public void onClick(View v) { int id = v.getId(); if (id == ID_PARENT || id == ID_TEXTVIEW) toggle(); } public boolean isChecked() { return isChecked; } public void setChecked(boolean chacked) { isChecked = chacked; refreshDrawableState(); } @Override public void toggle() { isChecked = !isChecked; refreshDrawableState(); } }
原文:https://stackoverflow.com/questions/11775710
更新时间:2023-11-20 21:11
最满意答案
区分大小写对DB没有太大影响,所以我认为这是故意的。
如果你不喜欢小写的列名,只需解决这个问题:
- 将列从“性别”重命名为“性别”。 添加迁移
- 将列重命名为“Gender”。 添加迁移
或者,您可以手动编辑生成的迁移代码
Case sensitivity does not make much difference to DB, so I believe this is intentional.
If you don't like lowercase column name, just work around this:
- Rename the column from "gender" to something like "genders". Add migration
- Rename column back to "Gender". Add migration
Alternatively, you can manually edit generated migration code
相关问答
更多-
这是因为您可能仍然存在现有的一对多关系 - 您刚刚删除关系一侧的导航属性,但另一侧仍然存在。 因为EF必须在您的表格中保留FK列。 EF只是将隐藏的FK列重命名为默认命名约定。 It is because you probably still have the existing one-to-many relationship - you've just removed navigation property on one side of the relation but the other side st ...
-
您正在使用Add-Migrations吗? 那么,您无需使用手动脚本手动更新数据库端。 您应该只在添加迁移脚本中执行此操作。 如果您手动运行数据库端重命名列的脚本,那么现有系统生成的MigrationScripts和数据库将不同步。 所以,在运行/回滚新/旧迁移脚本时,最终会出现错误。 根据我的理解,请尝试以下步骤 第1步: 在Visual Studio代码中重命名Model类的主键( RelId to RelationId)。 第2步:在软件包管理器控制台中运行Add-Migration RenameMy ...
-
未检测到EF 6自动迁移列名称大写重命名(EF 6 automatic migration column name uppercase rename not detected)[2022-12-14]
区分大小写对DB没有太大影响,所以我认为这是故意的。 如果你不喜欢小写的列名,只需解决这个问题: 将列从“性别”重命名为“性别”。 添加迁移 将列重命名为“Gender”。 添加迁移 或者,您可以手动编辑生成的迁移代码 Case sensitivity does not make much difference to DB, so I believe this is intentional. If you don't like lowercase column name, just work around ... -
为什么EF Migrations坚持要求我启用自动迁移?(Why does EF Migrations insist on me enabling automatic migrations?)[2022-02-11]
这意味着您当前模型的更改尚未添加到迁移中。 尝试: Add-Migration YourMigrationName Update-Database -Script 这将首先使用更新的模型更改创建迁移,然后您可以生成更新数据库SQL脚本。 It means there are changes to your current model that haven't been added to a migration. Try: Add-Migration YourMigrationName Update-Dat ... -
我使用错误处理来确定是否要求运行数据库更新。 在我的背景下,我把 public class MyAppDbContext : DbContext { public MyAppDbContext(string connectionString) : base(connectionString) { if (!Database.Exists()) { Database.SetInitializer(new MyAppDbI ...
-
在这个问题上似乎有一个长期未解决的票证,如下所述: rails bug报告 Rails的默认行为是使列为NULL,因为这可以防止在将空字符串转换回Ruby时对存在性检查等的误报。 您是否可以通过重新定义文本列以在mySQL控制台中使用NULL值来解决此问题? 编辑 您可以在迁移文件中执行此操作,这不是Rails方式,但它比向每个人发送电子邮件以更改其本地副本要好得多: MyModel.connection.execute "ALTER TABLE xxxxx CHANGE abcd ABCD text DE ...
-
这是因为EF Core默认表映射约定 (突出显示是我的): 按照惯例,每个实体都将设置为映射到与DbSet
属性同名的表,该属性在派生上下文中公开实体。 如果给定实体不包含DbSet ,则使用类名。 我想这与以前的EF不同。 重要的是,尽管您重命名了实体类,但如果保留旧的DbSet属性名称,则表名称不会更改。 This is because of the EF Core default table mapping convention (highlights are m ... -
您需要按以下顺序进行此更改: 将实体中的Name属性重命名为NewName 向项目添加新迁移 更改迁移以执行重命名而不是删除/创建, 但仅更改Up / Down方法的内容 编译并运行迁移 这就是我多次没有遇到问题的方式。 重要的是在创建迁移时不要触摸与迁移关联的模型快照。 PS:如果我没记错,EF甚至会检测到重命名是否符合某些(对我未知)约束,因为我认为在进行简单的属性/列重命名时,甚至不一定需要更改迁移。 You need to do this change in the following order: ...
-
就在这里。 表__MigrationHistory中的这个值是一个GZiped Xml,它包含EDMX模式。 我做了以下代码来检索EDMX模型( 此代码使用C#6 ) 您也可以通过以下链接访问我的要点: https : //gist.github.com/AlbertoMonteiro/45198dc80641ce1896e6 在这个要点中有一个C#5版本,您可以将其粘贴到控制台应用程序中。 #r "C:\Program Files (x86)\Reference Assemblies\Microsoft\ ...
-
删除任何不是字母的东西 将下划线( _ )预先放在不在字符串开头的大写字母 结果小写 df.columns Index(['FooBar', 'SpamEggs', 'Monty-Python'], dtype='object') df.columns.str.replace('[\W]', '')\ .str.replace('(?
相关文章
更多- RelativeLayout代码中设置属性
- [How to] Make custom search with Nutch(v 1.0)?(转)
- Solr拼写检查(spellCheck)配置和使用
- Guava Preconditions类-检查参数
- solr4.3之拼写检查SpellChecker功能
- 【Android】还原“微信”apk中的“发现”和“我”两个模块
- Apache Solr3.4应用实践(高亮 拼写检查 匹配相似)
- 是男人就下100层【第一层】——高仿微信界面(3)
- Windows Phone 获取app在商店中的版本(检查app的版本号)
- 是男人就下100层【第一层】——高仿微信界面(6)
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。