• <i id='nfa8g'><tr id='nfa8g'><dt id='nfa8g'><q id='nfa8g'><span id='nfa8g'><b id='nfa8g'><form id='nfa8g'><ins id='nfa8g'></ins><ul id='nfa8g'></ul><sub id='nfa8g'></sub></form><legend id='nfa8g'></legend><bdo id='nfa8g'><pre id='nfa8g'><center id='nfa8g'></center></pre></bdo></b><th id='nfa8g'></th></span></q></dt></tr></i><div id='nfa8g'><tfoot id='nfa8g'></tfoot><dl id='nfa8g'><fieldset id='nfa8g'></fieldset></dl></div>

      • <bdo id='nfa8g'></bdo><ul id='nfa8g'></ul>

    1. <legend id='nfa8g'><style id='nfa8g'><dir id='nfa8g'><q id='nfa8g'></q></dir></style></legend>
      1. <small id='nfa8g'></small><noframes id='nfa8g'>

        <tfoot id='nfa8g'></tfoot>

        扩展扩展 Layoutclass 的复合组件的问题

        时间:2024-04-14
          <bdo id='HaP6p'></bdo><ul id='HaP6p'></ul>
              <tbody id='HaP6p'></tbody>

            1. <legend id='HaP6p'><style id='HaP6p'><dir id='HaP6p'><q id='HaP6p'></q></dir></style></legend>
                <tfoot id='HaP6p'></tfoot>

                <small id='HaP6p'></small><noframes id='HaP6p'>

                  <i id='HaP6p'><tr id='HaP6p'><dt id='HaP6p'><q id='HaP6p'><span id='HaP6p'><b id='HaP6p'><form id='HaP6p'><ins id='HaP6p'></ins><ul id='HaP6p'></ul><sub id='HaP6p'></sub></form><legend id='HaP6p'></legend><bdo id='HaP6p'><pre id='HaP6p'><center id='HaP6p'></center></pre></bdo></b><th id='HaP6p'></th></span></q></dt></tr></i><div id='HaP6p'><tfoot id='HaP6p'></tfoot><dl id='HaP6p'><fieldset id='HaP6p'></fieldset></dl></div>

                  本文介绍了扩展扩展 Layoutclass 的复合组件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试扩展 LinearLayout 以用作复合组件.我已按照本教程进行操作:链接

                  I'm trying to extend a LinearLayout to use as a composite component. I have followed this tutorial: link

                  这看起来相当简单.但是,当我尝试为我的组件充气时,它总是失败.我从 logCat 得到的错误是找不到我的班级.对我来说似乎很奇怪,据我所知,android 在它自己的组件中搜索我的组件(我不确定这里的正确措辞,请参见下文).

                  Which seems fairly straight forward. However when I try to inflate my component it fails all the time. The error I get from logCat is that my class can't be found. It seems strange to me that as far as I can see android searches for my component among it's own components (I'm unsure about the correct wording here, please se below).

                  我写的代码如下:

                  main(当前活动):

                  main (the current activity):

                  //just the ordinary autogenerated eclipse code...
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.main);
                  }
                  

                  我的扩展线性布局:

                  public class DialPadView extends LinearLayout {
                  
                  public DialPadView(Context ctx, AttributeSet attr) {
                      super(ctx, attr);
                  }
                  
                  
                  @Override
                  protected void onFinishInflate() {
                      super.onFinishInflate();
                      ((Activity)getContext()).getLayoutInflater().inflate(R.layout.dialpadview, this);
                  }
                  

                  }

                  我的 main.xml 布局文件

                  My main.xml layout file

                  <?xml version="1.0" encoding="utf-8"?>
                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  >
                  <whalenut.testinflate.DialPadView
                      android:id="@+id/mydialpad"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      /></LinearLayout>
                  

                  最后是与我的复合组件一起使用的 dialpadview.xml 文件:

                  and finally my dialpadview.xml file to use with my composite component:

                  <?xml version="1.0" encoding="utf-8"?>
                  <DialPadView
                     xmlns:android="http://schemas.android.com/apk/res/android"
                     android:orientation="vertical"
                     android:layout_width="fill_parent"
                     android:layout_height="fill_parent">
                     <EditText 
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:text="test"/>
                  </DialPadView>
                  

                  当然,我所有的类文件都驻留在包 whalenut.testinflate

                  ofcourse all my class files resides in the package whalenut.testinflate

                  logCat 是这样说的:

                  logCat says this:

                  java.lang.RuntimeException:无法启动活动 ComponentInfo{whalenut.testinflate/whalenut.testinflate.TestInflateActivity}:android.view.InflateException:二进制 XML 文件第 2 行:膨胀类 DialPadView 时出错

                  java.lang.RuntimeException: Unable to start activity ComponentInfo{whalenut.testinflate/whalenut.testinflate.TestInflateActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class DialPadView

                  ...

                  原因:android.view.InflateException: Binary XML file line #2: Error inflating class DialPadView

                  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class DialPadView

                  ...

                  原因:java.lang.ClassNotFoundException: android.view.DialPadView in loader dalvik.system.PathClassLoader[/data/app/whalenut.testinflate-2.apk]

                  Caused by: java.lang.ClassNotFoundException: android.view.DialPadView in loader dalvik.system.PathClassLoader[/data/app/whalenut.testinflate-2.apk]

                  当我在 xml-文件,是不是因为一开始就没有找到它?

                  Why is Dalvik(?) searching for my class in the package android.view instead of whalenut.testinflate when I have given the fully qualified classname in the xml-file, is it because it doesn't find it there to begin with?

                  简而言之,为什么我不能,或者更确切地说,我如何在 android 中扩展扩展布局?

                  In short why can't I, or rather how do I inflate a extended Layout in android?

                  推荐答案

                  你需要改变你的 DialPadView 如下:

                  You need to change your DialPadView as follows:

                  <merge android:class="com.packageName.UIClassName"
                      android:id="@+id/DialView"
                      xmlns:android="http://schemas.android.com/apk/res/android"
                      android:orientation="vertical"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent">
                  <EditText android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:text="test"/>
                  </merge>
                  

                  然后在你的构造函数中调用它:

                  Then call this in your constructor:

                  super(context, attrs, defStyle);
                  
                  LayoutInflater inflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  
                  inflater.inflate(R.layout.DialView, this, true);
                  

                  然后您可以在主要活动中使用以下内容:

                  You can then use the following in your main activity:

                  DialView myDialView = new DialView(context);
                  
                  mainView.addView(myDialView);
                  

                  我希望这会有所帮助!

                  这篇关于扩展扩展 Layoutclass 的复合组件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:自定义 iPhone 用户界面组件 下一篇:Intent 启动新 Activity 的速度非常慢 :(

                  相关文章

                1. <legend id='p1cNM'><style id='p1cNM'><dir id='p1cNM'><q id='p1cNM'></q></dir></style></legend>

                    <tfoot id='p1cNM'></tfoot>

                      <i id='p1cNM'><tr id='p1cNM'><dt id='p1cNM'><q id='p1cNM'><span id='p1cNM'><b id='p1cNM'><form id='p1cNM'><ins id='p1cNM'></ins><ul id='p1cNM'></ul><sub id='p1cNM'></sub></form><legend id='p1cNM'></legend><bdo id='p1cNM'><pre id='p1cNM'><center id='p1cNM'></center></pre></bdo></b><th id='p1cNM'></th></span></q></dt></tr></i><div id='p1cNM'><tfoot id='p1cNM'></tfoot><dl id='p1cNM'><fieldset id='p1cNM'></fieldset></dl></div>

                      <small id='p1cNM'></small><noframes id='p1cNM'>

                        <bdo id='p1cNM'></bdo><ul id='p1cNM'></ul>