创建具有一组现有的小部件的自定义部件? [英] Creating a custom widget with a group of existing widgets?

查看:179
本文介绍了创建具有一组现有的小部件的自定义部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,如何做到这一点,但我仍然不很确定,所以我决定在这里问。

I've looked around on how to do this but I'm still not very sure, so I've decided to ask here.

我在找创建的小部件,将显示艺术家姓名,流派的列表,以及会场,他们将在被打。下面是4个部件组成一个ImageView的和3平原textViews的图片,我想以某种方式组,并创建1自定义部件,与我可以打电话,以显示相关信息的所有4个组成部分。

I'm looking to create a list of widgets that will display artist names, genre, and the venue they will be playing at. Below is a picture of 4 widgets consisting of an imageView and 3 Plain textViews that I want to somehow group and create 1 custom widget, with all 4 components that I can call to, to display the relevant information.

我也期待能有这个小部件自身复制到一组极限,展现不同的艺术家,流派和下面的其他场所之一。

I'm also looking to have this widget duplicate itself to a set limit, displaying different artists, genre, and venue one below the other.

我很卡在如何处理这一点,任何帮助将是巨大的,请!
在此先感谢!

I'm quite stuck on how to approach this, and any help would be great please! Thanks in advance!

图片:

http://puu.sh/hr9x4/b3bffdf263.jpg

编辑:扑通!任何帮助将是AP preciated!

edit: bump! any help would be appreciated!

推荐答案

创建自定义视图。

创建一个类的Widget和程度将其与线性布局。在构造函数中膨胀的布局包含布局(图像视图和3文本视图)。

create a class Widget and extent it with linear layout. In the constructor inflate a layout containing your layout(image view and 3 text views).

通过调用addView添加虚增视图类本身

Add the inflated view to the class itself by calling addView

写setter函数中,你会接受一个包含有关事件的信息和功能,只需设定值,相应的文本视图。事件类的对象

write setter functions in which you will accept the object of event class that contains information related to event and that function simply set the values to the appropriate text view.

Class Widget extends LinearLayout{
private TextView artistName;
public Widget(Context context) {
        super(context);

        View view =  LayoutInflater.from(getContext()).inflate(
                R.layout.widget, null);
        artistName = view.findViewById(R.id.artistName);
        this.addView(view);

    }

public void setName(Event event){
   artistName.setText(event.getArtistName());
}
}

在你的活动布局,你可以使用它作为

In your activity layout you can use it as

<pkg_name.Widget android:id="@+id/widget1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</pkg_name.Widget>

这篇关于创建具有一组现有的小部件的自定义部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆