私はJavaとAndroidSDKを初めて使用しますが、学習したいと思っています。私がやりたいのは、文または一般的な文字列を受け取り、1行のテキストのみを表示するアプリを作成することです。これはすでにコーディングされています。しかし、私がやりたいのは、「続行」などのボタンをクリックして「次の」行に進むことです。つまり、一度に少量のテキストを読んで、ボタンをクリックして続行することを提供しているだけです。
これは私がどこまで持っているかです:
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();
for (String s : words){
builder.append(s+" ");
tx.setText(builder.toString());
}
}});
}}
現在のところ、テキストはtextViewに読み込まれず、ボタンをクリックするとすべてのテキストが一度に読み込まれ、「再クリック」はサポートされません。
何か案は?
よろしくお願いします、
更新: 画面に印刷する単語を説明するためのカウンターを作成しました。別の質問があります。1つだけではなく、3つの単語(または任意の数の単語)を表示するにはどうすればよいですか?indexrangesをいじろうとしましたが、コツがつかめないようです。これが私の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 {
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]);
}
});
}}