Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void callMeInActivityOnCreate() {
- ListView listView = new ListView(this);
- CharSequence input = "Uniqueness happens when you fear attitude so authoratively that whatsoever you are sitting is your attraction.\r\n" +
- "When the seeker of man experiences the shames of the lover, the sainthood will know individual.\r\n" +
- "You have to disturb, and avoid harmony by your failing.\r\n" +
- "Hell of happiness will confidently shape a united wind.\r\n" +
- "Chaos is the only paradox, the only guarantee of dimension.\n" +
- "Light is not occult in over there, the underworld, or wonderland, but everywhere.\n" +
- "The embittered life of enlightenment is to follow with sainthood.\n" +
- "When one follows tantra and chaos, one is able to study love.\n" +
- "The suffering of discovering doers is unconditional.\n" +
- "Chaos is not the crystal satori of the sinner.\n" +
- "The purpose is a pure lotus.\n" +
- "As i have knowed you, so you must handle one another.\n" +
- "Reincarnation fears when you believe with totality.\n" +
- "Never develop the moon, for you cannot respect it.\n";
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 7000; i++) {
- sb.append('#').append(i).append(" ================\n").append(input);
- }
- listView.setAdapter(new PagingAdapter(sb));
- listView.setDivider(null);
- listView.setSelector(android.R.color.transparent);
- setContentView(listView);
- }
- class PagingAdapter extends BaseAdapter {
- /*
- sample logcat output:
- MainActivity D PagingAdapter =================================================
- D PagingAdapter text size: 6312890
- D PagingAdapter #items: 105002
- D PagingAdapter it took: 328ms
- D PagingAdapter =================================================
- */
- CharSequence text;
- List<Integer> list = new ArrayList<>();
- public PagingAdapter(CharSequence text) {
- this.text = text;
- long t0 = System.currentTimeMillis();
- int length = text.length();
- list.add(-1);
- for (int i = 0; i < length; i++) {
- if (text.charAt(i) == '\n') {
- list.add(i);
- }
- }
- list.add(length);
- long t1 = System.currentTimeMillis();
- Log.d(TAG, "PagingAdapter =================================================" );
- Log.d(TAG, "PagingAdapter text size: " + text.length());
- Log.d(TAG, "PagingAdapter #items: " + list.size());
- Log.d(TAG, "PagingAdapter it took: " + (t1 - t0) + "ms");
- Log.d(TAG, "PagingAdapter =================================================" );
- }
- @Override
- public int getCount() {
- return list.size() - 1;
- }
- @Override
- public Object getItem(int position) {
- return null;
- }
- @Override
- public long getItemId(int position) {
- return 0;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- TextView tv;
- if (convertView != null) {
- tv = (TextView) convertView;
- } else {
- tv = new TextView(parent.getContext());
- tv.setTextSize(24);
- }
- tv.setText(text.subSequence(list.get(position) + 1, list.get(position + 1)));
- return tv;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement