Android Widget中的Textview

时间:2014-03-15 19:55:18

标签: java android widget

我从一个小部件开始,我正在尝试在我的Main.xml中使用TextView。所以我只是添加一个拖放但我不知道如何使用代码找到它。在我使用的普通Android应用程序中

  

TextView text =(TextView)findViewById(R.id.name);

然后

  

text.setText( “BLABLA”);

但是当我在Widget中尝试它时,我得到一个错误,'findViewById'未定义此类型...有没有其他选择?我该如何申报呢?

谢谢!

1 个答案:

答案 0 :(得分:0)

对于小部件,您必须使用RemoteView。 http://developer.android.com/reference/android/widget/RemoteViews.html

RemoteViews有几种方法可以设置包含视图的值,例如: setTextViewText()。 http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewText%28int,%20java.lang.CharSequence%29