よろしくお願いします。
フラグメントにさまざまな文字列を挿入したいのですが、方法がわかりません。
この時点で物事をまとめるために借りたコードは次のとおりです。
パブリッククラス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)を更新できることがわかりますが、それを別のテキスト文字列と関連付けたいと思います。
ありがとうございました!