如何在android中制作自定义和复合对象?

时间:2014-05-01 17:38:59

标签: android eclipse android-widget compound-drawables

经过大量搜索,我发现了一篇很棒的文章,描述了如何制作复合对象。配方工作得很好,Eclipse在定制的小部件中显示它。奇妙。

http://mobile.cs.fsu.edu/creating-a-simple-compound-component-in-android/

只有一个问题,我需要一些问题。当我在布局中添加一些内容时,封闭层/对象的资源ID会按预期进行颠倒;也就是说,新对象通过auomagically接收新ID。问题是主要布局内的组件没有;因此,如果我需要使用finViewById来获取内部组件的视图,它们都具有相同的ID。有谁知道如何自动为复杂小部件的内部组件分配不同的id?我会尝试手动分配它们,但Eclipse不会显示复合对象的内部结构;所以没有帮助。

- 回应Xaver回答

是的,至少我认为我做过。如果我按照链接中的示例,我有类似的东西;现在我看到你在说什么,我只是通过将findviewbyId添加到自定义类来获取视图,因为这个

public class HorizontalNumberPicker extends LinearLayout {
    public HorizontalNumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater layoutInflater = (LayoutInflater)context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        layoutInflater.inflate(R.layout.horizontal_number_picker, this);

    View v = findViewbyID(R.id.btn_minus); // 
    }
}

我无法理解的内容,我很可能错误的是如何将我的代码挂钩到两个对象,即链接中的示例

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >

     <example.example.HorizontalNumberPicker
         android:id ="@+id/horizontal_number_picker"
         android:layout_width ="wrap_content"
         android:layout_height ="wrap_content" />

     <example.example.HorizontalNumberPicker2
         android:id ="@+id/horizontal_number_picker"
         android:layout_width ="wrap_content"
         android:layout_height ="wrap_content" />

</FrameLayout>

Horizo​​ntalNumberPicker construtor如何知道链接到object horizo​​ntal_number_picker或horizo​​ntal_number_picker2?

如果我在我的活动中添加

HorizontalNumberPicker obj1 = HorizontalNumberPicker (this,null);

指向horizo​​ntal_number_picker或horizo​​ntal_number_picker2的链接是什么?

顺便说一下我如何传递属性集?

0 个答案:

没有答案