代码中GwtBootstrap3中的引用元素

时间:2015-06-09 14:57:20

标签: gwtbootstrap3

我是GWT和GwtBootstrap3的新手,所以这可能是一个愚蠢的问题,但是如何在代码中引用我的***。ui.xml文件中的元素?

例如,我的***。ui.xml文件中有一个段落 -

    <b.html:Paragraph alignment="LEFT">
        Lorem Ipsum
    </b.html:Paragraph>     

我希望能够更改代码中的文本。 同样,如果我正在创建一个List但是无法在我的***。ui.xml文件中静态提供列表元素,并且需要在我的代码中提供它们,根据可用的选项,有没有办法做是什么?

任何建议/意见都将非常感激。

2 个答案:

答案 0 :(得分:1)

在研究GWT UiBinder后终于找到了一条路。 我在段落中插入了一个Label小部件,并使用 ui:field =&#39; myWidget&#39; 为我的Label提供了一个ID,然后在我的*** UIBinder.java中引用它:

@UiField Label myWidget;

并使用

在构造函数中设置文本
myWidget.setText("Dynamic text");

This can also be done without using widgets

答案 1 :(得分:1)

Rohit,我在你的回答中注意到你将初始段落小部件更改为Label元素。对于访问此问题且希望专门处理段落的其他人:将属性 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RecyclerView recyclerView = (RecyclerView) inflater.inflate( R.layout.activity_display_song_list_fragment, container, false); DisplaySongListFragment.ContentAdapter adapter = new DisplaySongListFragment.ContentAdapter(recyclerView.getContext()); recyclerView.setAdapter(adapter); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); return recyclerView; } //Adapter to display recycler view. public static class ContentAdapter extends RecyclerView.Adapter<DisplaySongListFragment.ViewHolder> { public ContentAdapter(Context context) { con = context; ReadFileFromSDCard(); } @Override public DisplaySongListFragment.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new DisplaySongListFragment.ViewHolder(LayoutInflater.from(parent.getContext()), parent); } // pass view holder object to method. @Override public void onBindViewHolder(DisplaySongListFragment.ViewHolder holder, int position) { HashMap<String, String> song = new HashMap<String, String>(); song = songsList.get(position); holder.name.setText(song.get(DisplaySongListFragment.KEY_artistName)); holder.description.setText(song.get(DisplaySongListFragment.KEY_trackCensoredName)); Glide.with(con).load(song.get(DisplaySongListFragment.KEY_artworkUrl30)).into(holder.avator); } @Override public int getItemCount() { return songsList.size(); } } static Context con; // provide layout to list row public static class ViewHolder extends RecyclerView.ViewHolder { public ImageView avator; public TextView name; public TextView description; public ViewHolder(LayoutInflater inflater, ViewGroup parent) { super(inflater.inflate(R.layout.item_list, parent, false)); avator = (ImageView) itemView.findViewById(R.id.list_avatar); name = (TextView) itemView.findViewById(R.id.list_title); description = (TextView) itemView.findViewById(R.id.list_desc); // Pass the selected Item Position to another activity. itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = v.getContext(); Intent intent = new Intent(context, DetailActivity.class); intent.putExtra(DetailActivity.EXTRA_POSITION, getAdapterPosition()); context.startActivity(intent); } }); } } 添加到html段落元素将允许您直接执行此任务

<强> UiBinder的

ui:field="myWidget"

<强>爪哇

xmlns:b.html="urn:import:org.gwtbootstrap3.client.ui.html"    

<b.html:Paragraph alignment="LEFT" ui:field="myWidget">
    Lorem Ipsum
</b.html:Paragraph>