public class Tab1 extends Fragment {
Context mContext;
public Tab1(Context context) {
mContext = context;
}
private TextSwitcher mSwitcher;
Button button1;
// Array of String to Show In TextSwitcher
String textToShow[]={"Apple","사과","banana","바나나","Window","창문"};
int messageCount=textToShow.length;
// to keep current Index of text
int currentIndex=-1;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_tab1, null);
super.onCreate(savedInstanceState);
// get The references
button1 = (Button) view.findViewById(R.id.button1);
mSwitcher = (TextSwitcher) view.findViewById(R.id.textSwitcher);
mSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
TextView myText = new TextView(getActivity());
//new TextView(MainActivity.this);
myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
myText.setTextSize(36);
return myText;
}
});
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
currentIndex++;
// If index reaches maximum reset it
if (currentIndex == messageCount)
currentIndex = 0;
mSwitcher.setText(textToShow[currentIndex]);
}
});
return view;
}
}