【发布时间】:2013-01-23 21:50:07
【问题描述】:
提前感谢您的帮助。
我想在片段中注入不同的字符串,但我不确定如何。
此时我借用的代码是:
公共类 MyFragment 扩展 Fragment{
int mCurrentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfragment_layout, container,false);
TextView tv = (TextView ) v.findViewById(R.id.tv);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setText("You are viewing the page #" + mCurrentPage + "\n\n" +"\n\n" + "Swipe Horizontally left / right");
return tv;
}
这是我想做的,只是我想根据它所在的页面显示不同的文本字符串。我在此示例代码中看到可以更新页码 (mCurrentPage),但我想将其与不同的文本字符串相关联。
谢谢!
【问题讨论】:
-
欢迎来到stackoverflow!您能否更好地解释一下您正在使用什么并添加一些补充标签(如果您能找到合适的)?
-
感谢 Daniele 的友好请求。我添加了更多标签。我有点不知所措。 :-)
标签: android string switch-statement fragment