首页 \ 问答 \ 在我的自定义视图上阅读Android属性(Reading Android attributes on my custom view)

在我的自定义视图上阅读Android属性(Reading Android attributes on my custom view)

我创建了一个自定义布局类(扩展RelativeLayout)并将TextView作为布局的一部分。

我想将XML中声明的属性应用到我的TextView,无论如何我可以读取android属性(不是我的自定义属性,那部分已经被处理)。

例如,在我的XML中,我将拥有:

<my.custom.MyLayout
    android:layout_width="100dp"
    android:layout_height="20dp"
    android:text="SomeText" /> 

我想读取text属性并将其应用于我的TextView(目前它正在应用于RelativeLayout),而不是创建我自己的属性并读取它。

我的自定义布局是这样的:

public class MyLayout extends RelativeLayout {

    private TextView textView;
    public void MyLayout(final Context context, final AttributeSet attrs) {
        /**Read android attributes and apply it to TextView **/
        ??
    }

我目前的解决方案是创建自定义属性并阅读它们,但我觉得这不是一个好的解决方案,因为我将复制声明为TextView的每个属性。

有关我当前解决方案的更多信息

我有一个名为myText的自定义属性,我将其用于将XML中声明的文本应用于TextView。

在我的布局XML中:

myNameSpace:myText="SomeText"

并在我的Java类中阅读:

String text= a.getString(R.styleable.MyStyleable_myText);
textView.setText(text);

我想摆脱我的自定义属性并阅读“android:”属性。


I have created a custom layout class (extends RelativeLayout) and have a TextView as part of the layout.

I want to apply the properties declared in XML to my TextView, is there anyway I can read the android attributes (not my custom attributes, that part is already taken care of).

For example in my XML I'll have this:

<my.custom.MyLayout
    android:layout_width="100dp"
    android:layout_height="20dp"
    android:text="SomeText" /> 

I want to read the text attribute and apply it to my TextView (currently it is being applied to the RelativeLayout) instead of creating my own attribute and reading it.

My custom layout is something like this :

public class MyLayout extends RelativeLayout {

    private TextView textView;
    public void MyLayout(final Context context, final AttributeSet attrs) {
        /**Read android attributes and apply it to TextView **/
        ??
    }

My current solution is creating custom attributes and reading them, but I feel that is not a good solution as I'll be duplicating every attribute declared to TextView.

More info about my current solution.

I have a custom attribute called myText which I use to apply the text declared in XML to my TextView.

In my layout XML :

myNameSpace:myText="SomeText"

And read it in my Java class :

String text= a.getString(R.styleable.MyStyleable_myText);
textView.setText(text);

I'm looking to get rid of my custom attributes and read "android:" attributes.


原文:https://stackoverflow.com/questions/33163042
更新时间:2021-09-13 20:09

最满意答案

IgnoreUrlPrefixes设置应该处理这个。

只需在那里添加路由前缀,Sitecore就应该忽略它。

 <setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/>

更多信息在这里

http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-with-the-sitecore- ASPNET,cms.aspx


The IgnoreUrlPrefixes setting should handle this.

Just add the route prefix in there and Sitecore should ignore it.

 <setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/>

More info here

http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-with-the-sitecore-aspnet-cms.aspx

相关问答

更多
  • 在某些情况下,合并这两者可能会带来巨大好处。 MVC并不适合内容驱动的网站。 但是,具有结构化流程和多个数据表示的Web应用程序从中受益匪浅。 Sitecore在多个数据展示方面有一定的局限性 - 您只能在一个项目上定义一组设计细节。 如果您没有WYSIWYG编辑或轻松一键式预览的要求,则可以使用Sitecore作为数据存储库,并利用来自其管道(例如语言)的一些Context值。 Sitecore HTTP管道需要进行一些修改才能使其工作: 1)如果在IIS6中使用aspx扩展来让ASP.NET处理MVC请 ...
  • 以下是我的一个项目的工作示例。 自定义路线注册: namespace Test.Project.Pipelines.Initialize { public class InitRoutes : Sitecore.Mvc.Pipelines.Loader.InitializeRoutes { public override void Process(PipelineArgs args) { RegisterRoutes(RouteTabl ...
  • 我决定尝试添加一些调试到Sitecore 7.2的全新安装。 我创建了以下简单的类: using Sitecore.Diagnostics; using Sitecore.Pipelines; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Web; namespace SCMVC72.Pipelines { public class ...
  • 您的出发点将是Sitecore MVC开发人员参考,并且发布了一个很棒的视频教程,这是一步一步: Sitecore MVC - 入门(第1部分) 。 您可能还想阅读: John West的Sitecore MVC博客帖子 ,这些主要与Sitecore 6.6相关,但很多理论仍然相同。 学习Sitecore MVC 开始使用Sitecore MVC作为asp.net mvc开发人员 还有很多其他帖子,你需要谷歌这些,不要指望在SO上发布全面的列表。 如果您不熟悉MVC,那么您需要阅读,学习和理解这些技巧。 它 ...
  • 所以在完成这个工作之后 这是简单的事情,使这项工作。 您必须将/ signalr和/ signalr /集线器添加到SignalR的忽略路径以与Sitecore配合使用。 在我完成了这一步之后,我能够在Application_Start中正确地看到MapHubs连 ...
  • 我不认为没有它你的网站会破坏,但我强烈建议添加它以获得完整的xDB支持。 没有它,我相信你所有的流量都可能被视为“机器人”而不会被跟踪。 一些使用访客标识引用的文章: http://www.daveleigh.co.uk/sitecore-7-5-mvc-enabling-analytics-xdb/ http://www.daveleigh.co.uk/sitecore-xdb-and-setting-up-mongo-副本集/ I don't think your site will break wit ...
  • IgnoreUrlPrefixes设置应该处理这个。 只需在那里添加路由前缀,Sitecore就应该忽略它。 更多信息在这里 http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-wi ...
  • 检查App_Config\Include文件夹中是否存在Sitecore.MVC.config 。 或者打开http://.../sitecore/admin/showconfig.aspx url。 看看MVC设置是否存在。 例如: Check if Sitecore.MVC.config is there in App_Config\Include folder. Or open http://.../sit ...
  • 您可以创建自定义路线。 routes.MapHyphenatedRoute( name: "Hyphenated URL", url: "{controller}/{action}", defaults: new { scItemPath = "/Home/{controller}/{action}" } ); 这里的想法是用连字符拦截路由值并将它们转换为您想要的格式。 没有连字符的网址将保持不变。 Sitecore仍然需要处理scItemPath的能力。 public s ...
  • 这是Glass Mapper的一个已知问题,已修复: https://github.com/mikeedwards83/Glass.Mapper/issues/100 您应该更新到最新的Glass Mapper版本以摆脱这个问题。 This is a known issue from Glass Mapper and has been fixed: https://github.com/mikeedwards83/Glass.Mapper/issues/100 You should update to th ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。