Android SDK: Show one line at a time and proceed with onClick -


i'm new java , android sdk i'm willing learn. want build app take sentence, or generic string , displays 1 line of text, coded. want proceed "next" line clicking button called "proceed". in short offers read little amount of text @ time , proceed b clicking button.

this how far i've got:

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".displaymessageactivity"     android:orientation="horizontal" >      <textview         android:id="@+id/text_box"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textsize="50sp"         android:maxlines="1" />      <button         android:id="@+id/next_button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centervertical="true"         android:text="@string/next"         android:onclick="nextline"         android:textsize="15sp" />  </relativelayout> 

mainactivity.java:

package com.xxx.xxx.xxx;  import android.app.activity; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview;  public class mainactivity extends activity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);      string s = "iphone swag fanny pack, try-hard master cleanse pop-up elit deserunt vinyl. odio mustache hoodie yolo fap. vegan godard labore tempor. farm-to-table aute craft beer, yolo bicycle rights artisan semiotics. cosby sweater readymade eiusmod consectetur fap stumptown. cliche keytar accusamus blue bottle, wayfarers locavore selfies elit aliqua chillwave lo-fi helvetica enim. irony tofu blog, fap pickled pariatur odio wolf cliche vice sint pitchfork eiusmod cosby sweater polaroid.";     final string[] words = s.split("\\s+");      button b = (button) findviewbyid(r.id.next_button);      b.setonclicklistener(new onclicklistener() {        @override        public void onclick(view v) {            textview tx = (textview) findviewbyid(r.id.text_box);            stringbuilder builder = new stringbuilder();            (string s : words){              builder.append(s+" ");            tx.settext(builder.tostring());        }     }});  }} 

as of no text loaded textview , button loads of text @ once when clicked on no support "reclick" it.

any ideas?

best regards,

update: i've made counter account word should printed on screen. have question: how go make tre words (or number of words) show instead of one? tried fiddle indexranges can't seem hang of it. how mainactivity.java looks now:

package com.xxx.xxx.xxx;  import android.app.activity; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview;  public class mainactivity extends activity {      int counter;     string s = "iphone swag fanny pack, try-hard master cleanse pop-up elit deserunt vinyl. odio mustache hoodie yolo fap. vegan godard labore tempor. farm-to-table aute craft beer, yolo bicycle rights artisan semiotics. cosby sweater readymade eiusmod consectetur fap stumptown. cliche keytar accusamus blue bottle, wayfarers locavore selfies elit aliqua chillwave lo-fi helvetica enim. irony tofu blog, fap pickled pariatur odio wolf cliche vice sint pitchfork eiusmod cosby sweater polaroid.";     final string[] words = s.split("\\s+");      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         final textview tx = (textview) findviewbyid(r.id.text_box);         counter = 0;         tx.settext(words[counter]);      button b = (button) findviewbyid(r.id.next_button);      b.setonclicklistener(new onclicklistener() {        @override        public void onclick(view v) {            counter++;            tx.settext(words[counter]);        }     });  }} 

your code assigns textview value on every iteration adding 1 word after each iteration. that's why text loaded.

   public void onclick(view v) {        textview tx = (textview) findviewbyid(r.id.text_box);        stringbuilder builder = new stringbuilder();         (string s : words){          builder.append(s+" ");          tx.settext(builder.tostring());        } 

if want display 1 word per click, make counter acts index words array , increments after every click. , assign "current index word" text field.


Comments

  1. This page contains the necessary information The Samsung Galaxy M52 is going to be published very soon if you feel free you can visit my site Samsung M52 Release Date

    ReplyDelete

Post a Comment

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -