【发布时间】:2014-10-26 18:53:43
【问题描述】:
下面的代码有问题
setContentView(R.layout.activity_main);
TextView myLocation = (TextView)findViewById(R.id.txtAddress);
myLocation.setText("123 Main St New York, NY");
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);
我的问题在于说的部分
mainLayout.addView(myLocation);
它抱怨“mainLayout 无法解决”,这正是我在引号中所说的错误。
有人对如何解决这个问题有建议吗?
【问题讨论】:
-
您可以编辑问题并准确粘贴错误消息的内容吗?
-
确切的错误是 mainLayout cannot be resolved
-
您需要从 XML 中的 id 属性中找到您的布局“mainLayout”,setContentView 之后,mainLayout.addView(myLocation) 之前;所以 mainLayout 可以解决 - 就像你为 TextView myLocation 所做的那样 - 但应该为布局完成 - RelativeLayout 或 LinearLayout - 无论你在 XML 中设置了什么
-
你能举个例子吗?
-
如果对我有一个 RelativeLayout 有帮助