我有一个类,它以编程方式更改布局的背景和textview字符串,需要使用viewpager实现。但是settext函数不适用于更改文本;
public class ImageFragment extends Fragment {
private int imageResourceId;
private string menu_description;
public ImageFragment(int imageResourceId, string menu_description) {
this.imageResourceId = imageResourceId;
this.menu_description = menu_description;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("Test", "hello");
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.layout_menu, container, false);
// ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);
// imageView.setImageResource(imageResourceId);
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.main_layout);
layout.setBackgroundResource(imageResourceId);
TextView textview = (TextView) view.findViewById(R.id.menu_description);
textview.setText(menu_description);
return view;
} }