简体   繁体   English

我没有在下面的代码中为视图对象(即v)获取addView()方法?

[英]I am not getting addView() method for object of view i.e v in my code below?

I want to add button dynamically in this view ie v 我想在此视图中动态添加按钮,即v

public class MyviewActivity extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LayoutInflater inflater=this.getLayoutInflater();
        View v=inflater.inflate(R.layout.main, null, true);//view
    }
}

The View class doesn't have an addView method. View类没有addView方法。 You need to use one of the base classes that extends ViewGroup such as LinearLayout . 您需要使用扩展ViewGroup的基类之一,例如LinearLayout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到错误消息,即必填字段:缺少频道 - I am getting error i.e Required field: Channel is missing 我想单击按钮将我的第一个活动的内容(即Java代码)复制到片段中 - I want to copy the content of my first activity (i.e the java code ) to my fragment on the click of a button 我可以在Android Studio中运行API级别7(即eclair)的代码吗? - Can i run my code of API level 7 i.e eclair in android studio? 如何通过inflate()方法访问我的资源,即菜单? - How to access my resource i.e menu through inflate() method? 我不明白为什么在我的可扩展列表视图的 onChildClick 方法中出现致命异常 - I dont understand why I am getting a fatal exception in my onChildClick method for my expandable list view 下面是我的代码我想通过使用下面的代码将图像 url 发送到服务器而不是完整的图像 我在 android studio 中收到服务器 500 错误 - below is my code i want to send the image url to server not the complete image by using below code i am getting server 500 error in android studio 我的代码中出现错误 - I am getting an error in my code 我正在开发 OCR 阅读器应用程序。 下面是我的 java 代码。 我的问题是如果一个方法完成了如何开始另一种方法? - I am working on OCR reader application. below is my java code. My question is how to start another method if one is completed? 我正在通过回收站视图设置静态图像,但我收到空指针异常,这是我的代码和错误 - I am setting static image through recycler view but I am getting null pointer exception here is my code and eror 我越来越像下面的例外 - i am getting exceptiion like below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM