textviewについて

11 views
Skip to first unread message

160yen

unread,
Jul 11, 2010, 10:12:03 PM7/11/10
to 日本Androidの会
ソースファイルでtextviewの文字列を設定したいのですが、
現在、下記のように記述しているのですが、
「テスト2」が一番上に来て、テスト1が表示されません。
ネットで調べてみたのですが、1つのtextviewの表示の方法しか載っていませんでした。

TextView01
ImageView01
TextView02
とテキストとテキストの間に画像を表示しています。

画像はレイアウトファイルで設定し、
テキストの文字列は、ソースファイルで設定したいのですが、
どなたかご教示下さい。


ソースファイル
import sample.Sc.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class Firesc2 extends Activity {

@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.show);

TextView tv = ( TextView ) findViewById (R.id. TextView01 );
tv. setText ("テスト1");
findViewById (R.id. TextView02 );
tv. setText (" テスト2");
}



レイアウトファイル
show.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:text="@+id/TextView01"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

<ImageView
android:id="@+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/backsou">
</ImageView>

<TextView
android:text="@+id/TextView02"
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

</LinearLayout>

てんき

unread,
Jul 11, 2010, 10:21:16 PM7/11/10
to android-g...@googlegroups.com
てんきです。

下記ソースコードですと、「TextView01」に2回文字列を指定していることになっています。
おそらくやりたいこととしては、以下のようになるのではないでしょうか。

import sample.Sc.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class Firesc2 extends Activity {

@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.show);

TextView tv = ( TextView ) findViewById (R.id. TextView01 );
tv. setText ("テスト1");
findViewById (R.id. TextView02 );

tv = ( TextView ) findViewById (R.id. TextView02 );


tv. setText (" テスト2");
}

または、

TextView tv = ( TextView ) findViewById (R.id. TextView01 );
tv. setText ("テスト1");
findViewById (R.id. TextView02 );

TextView tv2 = ( TextView ) findViewById (R.id. TextView02 );
tv2. setText (" テスト2");

以上です。

2010年7月12日11:12 160yen <160...@gmail.com>:

> --
> このメールは Google グループのグループ「日本Androidの会」の登録者に送られています。
> このグループに投稿するには、android-g...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-group-j...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-group-japan?hl=ja からこのグループにアクセスしてください。
>
>

--
☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆
Digital Rabbit - てんき
Mail:tenki...@gmail.com
ditital....@gmail.com
☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆゜・*:.。. .。.:*・゜☆

てんき

unread,
Jul 11, 2010, 10:23:26 PM7/11/10
to android-g...@googlegroups.com
失礼しました。
ソース内容を間違ってしまいました…

以下、修正です。


import sample.Sc.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class Firesc2 extends Activity {

@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.show);

TextView tv = ( TextView ) findViewById (R.id. TextView01 );
tv. setText ("テスト1");

tv = ( TextView ) findViewById (R.id. TextView02 );
tv. setText (" テスト2");
}
または、

TextView tv = ( TextView ) findViewById (R.id. TextView01 );
tv. setText ("テスト1");

TextView tv2 = ( TextView ) findViewById (R.id. TextView02 );
tv2. setText (" テスト2");

これで行けるはずです。

2010年7月12日11:21 てんき <tenki...@gmail.com>:

160yen

unread,
Jul 12, 2010, 8:43:04 AM7/12/10
to 日本Androidの会
てんきさん、アドバイスありがとうございます。

本当に助かりました!!!
ありがとうございました!
Reply all
Reply to author
Forward
0 new messages