• 締切済み

質問Androidでのテキストの読み込み方

Androidでのテキストファイル、バイナリファイルからの読み込み方。 現在Androidでクイズアプリを作っており、基本の構造はできたのですが、 問題文と選択肢の文章をコード内に直接記入している状態です。 そこでファイルから1行ずつ読み込んでTextViewとRadioButtonのテキストに表示するようにしてコードを すっきりさせたいのですが、ファイルの読み込みを1行ずつ行い表示させるやりかたがわかりません。 よければ教えていただけるとありがたいです。初心者にわかるように書いているサイトなども あれば教えてもらいたいです。

みんなの回答

回答No.2

#1は間違い。 そもそもリソース(ファイル)の扱い方そもそも理解している?

gaku0304
質問者

補足

データベースは触ったことなく、プログラミングの経験はほとんどないのでリソースの扱いはほとんど理解していない状態です。 ただテキストのみをテキストビューなどに表示するクラスはネットで調べて見つかったのですが、 1行ずつ指定して取り出すやりかたについては探しても見つからなかったのでこちらで 質問いたしました。

全文を見る
すると、全ての回答が全文表示されます。
回答No.1

Zend Debuggerの扱い方そもそも理解している?

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • Android用のアプリケーション開発

    私は下記の開発環境でAndroid用のアプリケーションを開発しています。 Eclipse Version: 3.6.2 Android 2.3.3 TableLayoutで3行3列のテーブルの、4行目の3列目と5行目の3列目を結合したいですが出来ませんでした。 下記のソースコードの「あいうえおかきくけ」の部分を画像にして2行分の大きさで表示させたいです。 Android用のアプリケーションの開発が初めてですが、ご教授を頂けると幸いです。 下記はソースコードの一部です。 --------------------------------------- //1行目 TextView text1 = new TextView(this); text1.setText("         "); TextView text2 = new TextView(this); text2.setText("投資情報"); TextView text3 = new TextView(this); text3.setText("         "); TableRow tableRow1 = new TableRow(this); tableRow1.addView(text1); tableRow1.addView(text2); tableRow1.addView(text3); tableLayout.addView(tableRow1, createParam(FP, WC)); //2行目 TextView text4 = new TextView(this); text4.setText("先週の情報"); TableRow tableRow2 = new TableRow(this); tableRow2.addView(text4); tableLayout.addView(tableRow2, createParam(FP, WC)); //3行目 TextView text8 = new TextView(this); text8.setText("2011年11月7日"); text8.setWidth(480); text8.setGravity(Gravity.RIGHT); TableRow tableRow3 = new TableRow(this); TableRow.LayoutParams rowLayout3 = new TableRow.LayoutParams(); rowLayout3.span = 3; tableRow3.addView(text8, rowLayout3); tableLayout.addView(tableRow3, createParam(FP, WC)); //4行目 ImageView image1 = new ImageView(this); image1.setImageResource(R.drawable.tyuugoku); TextView text11 = new TextView(this); text11.setText("国名"); TextView text12 = new TextView(this); text12.setText("あいうえおかきくけ"); TableRow tableRow4 = new TableRow(this); TableRow.LayoutParams rowLayout4 = new TableRow.LayoutParams(); rowLayout4.column = 2; tableRow4.addView(image1); tableRow4.addView(text11); tableRow4.addView(text12); tableLayout.addView(tableRow4, createParam(FP, WC)); //5行目 TextView text13 = new TextView(this); text13.setText("記事リード"); TableRow tableRow5 = new TableRow(this); TableRow.LayoutParams rowLayout5 = new TableRow.LayoutParams(); tableRow5.addView(text13); tableLayout.addView(tableRow5, createParam(FP, WC)); ---------------------------------------- 長文になりましたが、どうぞ宜しくお願い致します。

    • ベストアンサー
    • Java
  • Androidのレイアウトについて

    こんばんは ちょっとアンドロイドのレイアウトでちょっと戸惑って質問来ました。 添付画像のように画像の横のテキストを2行(本来は右より)で配置したいのですが、うまく設定出来ません。 TableLayoutをどういじってもダメ 泣 AbsoluteLayoutを見つけましたが、上部のテキストが長い時に使えない事がわかりどうしようもありません。 どのようにしたら、画像の横にテキスト行をニ行置けるでしょうか? <TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_width="fill_parent"> <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_height="wrap_content"></ImageView> <LinearLayout android:id="@+id/linearLayout5" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="TextView" android:layout_width="wrap_content" android:id="@+id/textView5" android:layout_height="wrap_content"></TextView> </LinearLayout> <TextView android:text="TextView" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </TableRow> </TableLayout> 取り敢えず今の問題の所が上です。 【知りたい事】 画像の横にニ行以上テキストを配置したい。 【やった事】 いろいろやり過ぎて書ききれません 泣 【開発環境】 Eclipse 何卒お知恵を貸してください。お願します。

    • ベストアンサー
    • XML
  • android.R.id.text1はどこにある

    androidアプリ開発 を読みながら、作業しています。 ( 184ページ ) サンプルのコード SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, g_list, android.R.layout.simple_expandable_list_item_1, new String[] { "group_title"}, new int[]{android.R.id.text1 }, c_list, android.R.layout.simple_expandable_list_item_2, new String[] {"child_title", "child_text" }, new int[] { android.R.id.text1, android.R.id.text2 } ); elv.setAdapter(adapter); elv.setOnChildClickListener( new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1); Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show(); return false; } } は、動くのですが、欲張って SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, g_list, android.R.layout.simple_expandable_list_item_1, new String[] { "group_title"}, new int[]{android.R.id.text1 }, c_list, android.R.layout.simple_expandable_list_item_2, new String[] {"child_title", "child_text" }, new int[] { android.R.id.text2, android.R.id.text3 } ); elv.setAdapter(adapter); elv.setOnChildClickListener( new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { TextView txt = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text1); Toast.makeText(AddrListShowActivity.this, txt.getText(), Toast.LENGTH_LONG).show(); TextView txt2 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text2); Toast.makeText(AddrListShowActivity.this, txt2.getText(), Toast.LENGTH_LONG).show(); TextView txt3 = (TextView) ((TwoLineListItem) v).findViewById(android.R.id.text3); Toast.makeText(AddrListShowActivity.this, txt3.getText(), Toast.LENGTH_LONG).show(); return false; } } とすると、android.R.id.text3  が原因で動きません。 そもそも、android.R.id.text1 の  text1 は何処にあるのでしょうか。 アドバイスよろしくお願いします。  

  • 【Android開発】ボタンのテキスト表示

    Android初心者です。現在画面遷移先の画面に配列で設定した質問文、選択肢を表示するアプリを制作しています。質問文はTextView、選択肢は2つのButtonにテキストとして表示する。画面遷移した後にsetQuestion()、setChoiceを呼び出したいんですが実機で試したところ、画面遷移した後に「問題が発生しため、(アプリ名)を終了します」とポップアップが出て、アプリが落ちます。 この2つのメソッドをonCreateに入れるのは間違なのでしょうか?どうすればうまくいきますか?初心者なのでうまく書けてないかも知れません。 よろしくお願いします。 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sub); setChoice(); setQuestion();  } int number = 0; //質問番号 //選択肢 Button button1; Button button2; Button button3; Button button4; //質問文を配列に格納 static String question[] = { "質問文1", "質問文2", }; //選択肢 static String choice[][] = { {"1番", "2番", "3番", "4番"}, {"1番", "2番", "3番", "4番"}, }; //問題の回答 static String answer[] = { "2番", "4番" }; //出力 //質問文を表示 public void setQuestion() { String setQuestion = question[number]; // TextView question = (TextView) findViewById(R.id.Question); question.setText(setQuestion); } //選択肢の表示 public void setChoice() { TextView button1 = (Button) findViewById(R.id.button1); TextView button2 = (Button) findViewById(R.id.button2); button1.setText(choice[number][0]); button2.setText(choice[number][1]); } xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Question" android:id="@+id/Question" android:textSize="40dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="81dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:textSize="30dp" android:onClick="choiceClick" android:layout_above="@+id/button2" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:textSize="30dp" android:onClick="choiceClick" android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/button1" android:layout_alignStart="@+id/button1" />

  • androidのサンプルソースについての質問

    このページを参考に学習をしていたのですが http://libro99.appspot.com/index3?id=29&page=2&label=android .javaに追加するぶぶんで text.setText(selradio.getText()); ~~~~ の波線の部分のエラーをどうしても消すことができず 困っています package test.radiobutton; import android.app.Activity; import android.os.Bundle; import android.widget.RadioButton; import android.widget.RadioGroup; public class radiobuttontest extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); RadioGroup group = (RadioGroup)this.findViewById(R.id.group); RadioButton radio1 = (RadioButton)this.findViewById(R.id.radio1); RadioButton radio2 = (RadioButton)this.findViewById(R.id.radio2); radio2.setChecked(true); int selid = group.getCheckedRadioButtonId(); RadioButton selradio = (RadioButton)this.findViewById(selid); text.setText(selradio.getText()); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <RadioGroup android:id="@+id/group" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:text="@string/radio1_label" android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:text="@string/radio2_label" android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RadioGroup> </LinearLayout> これ以上はかけませんがページの指示通りにやってるつもりです どなたかご教授お願いします

    • ベストアンサー
    • Java
  • Androidアプリのテキスト差分比較アプリ

    Androidのアプリで、2つのテキストの違いを見つけることのできるテキスト差分比較アプリを探しています。 WINDOWSのフリーソフトではいくつも見つかるんですが、Androidではなかなか見つからなかったり、文字化けして使えなかったりします。 ネット上での差分比較サイトでは、テキストをコピー貼り付けするためにアプリを切り替えると前に貼り付けたテキストがアプリ再読み込みで消え去ってしまいます。 どなたか、有用なアプリを教えて下さい。 よろしくお願いします。

  • Androidのレイアウトについて

    XMLで作成したTextViewを処理中に色を変えることは出来ないのでしょうか? 下記のようにやれば実装できるのでは?と思ってやってみましたがダメでした、 XMLファイルを使った方法で文字の色を変更する事は可能ですか? hogehoge.xml---------------------------------------------- <TextView android:id="@+id/text" android:textColor="@color/black" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hogehoge" /> hogehoge.java--------------------------------------------- EditText textView=(EditText)findViewById(R.id.text); textView.setTextColor(Color.RED); ---------------------------------------------------------

  • Androidでの問題集のつくりかた

    Androidでの問題集のつくりかた、データの取り扱いについて。 Anbroidでの問題集の作り方。私はAndroidのアプリとしてことわざの問題集を作っています。テキストで問題を、ラジオボタン3つにそれぞれ選択肢をつけ、ラジオボタンを選んだ状態で回答ボタンを押すと正誤判定と解説が表示されるアプリです。問題表示と正誤判定まではできたのですが、現在は問題を直接テキストに書いている状態です。 そこで、保存しているファイルなどから問題文、選択肢などにテキストを読み込めるようにしたいのですが、当方データベースなどについても全然知識がないのでまずは簡単な方法をやってみたいと思っています。 調べてみたところシーケンシャルファイルを作れば少しのデータなら簡単に扱えるとありました。なのでAndroidでシーケンシャルファイルの扱い方を教えて欲しいです(読み込むプログラムと表示するプログラムの書き方など)。やりかたの書いてあるサイトなどでもありがたいです。 シーケンシャルファイルじゃなくとも簡単にできるものがあれば教えていただきたいです。 とりあえず10問ほど作れれば問題ないです。

    • ベストアンサー
    • Java
  • Android実行時のエラー(実機にて)

    Androidアプリ開発初心者の者です。 下記に記載しています書籍のアプリを 作成中にエラーが起こりスマホのアプリが強制終了と いう形で落ちてしまいます。 【アプリを作ろう! ゼロから学ぶアプリの作成から公開まで Android2.3~4.1対応】  http://ec.nikkeibp.co.jp/item/books/P96130.html Eclipseのコード画面は以下のようになっています。 【OmikujiActivity.java】 package makeApplication.omikuji; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class OmikujiActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 文字を表示する TextView tv = (TextView) findViewById(R.id.action_settings); tv.setText("おみくじアプリ"); } } 下から4行目のaction_settingsの部分は書籍では補完候補で、 hellow_view:int - R.idがポップアップ表示されているのですが、 現在私のコード画面には表示されず、仕方なくaction_settingsを選択しています。 上記で保存し実行すると、スマホの実機の方で「おみくじ」と表示されず、 そのまま強制終了してしまい再度実行を促されてしまいます。 action_settingsの部分が原因なのかどうかよく 分からないのでお詳しい方ぜひ教えて頂きたいです。 宜しくお願い致します。

    • ベストアンサー
    • Java
  • VBでのテキストファイルの 読み込み & 書き出し について

    テキストファイルの中味を全部読み込んで、テキストボックスに表示するというコードをOpenステートメントを使って書いています。 その際、1つの種類のデータを1つのテキストファィルとして書き出し&読み込み しているのですが、これですと種類が増えていくとともにテキストファイルの 数もどんどん増えてしまい効率が悪いです。 で、それらを1つのテキストファイルにまとめておいて、中をセクションに 区切って、それを読み込み&書き出しする方法はあるのでしょうか? データが1行ですと分かるのですが、それぞれが長いテキストデータを1つの テキストファイルに区切って書き出し&読み込みする方法が分かりません。 どなたか教えてください!!!!!!! よろしくお願いします。