Created
September 28, 2016 12:18
-
-
Save fobidlim/ed9c2fc9b1bb3dce53b18f68bba2ed63 to your computer and use it in GitHub Desktop.
TextFragment extends BaseFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TextFragment extends BaseFragment { | |
private TextView mTextView; | |
private ArrayList<String> mTexts; | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mTexts = new ArrayList<>(); | |
} | |
@Nullable | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |
@SuppressLint("InflateParams") | |
View view = LayoutInflater.from(context).inflate(R.layout.f_text, null); | |
mTextView = (TextView) view.findViewById(R.id.f_text_textview); | |
addText(); | |
return view; | |
} | |
private void addText() { | |
for (int i = 1; i <= 10; i++) { | |
mTexts.add(String.valueOf(i)); | |
} | |
} | |
@Override | |
public void change() { | |
if (mTexts.size() > 0) { | |
int randomPosition = RandomUtils.getInt(mTexts.size()); | |
mTextView.setText(mTexts.get(randomPosition)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment