0

書籍アプリケーション用のビューページャーを作成しようとしています。私は android turorial http://developer.android.com/training/animation/screen-slide.htmlの助けを借りて、残りは自分でやろうとしています。ビューの変更 (クリック時にテキストビューのテキスト フォントを変更) がページ内で有効になっていないところに行き詰まっています。

ここにいくつかのコード

activity_main.xml

<TextView
        android:id="@+id/titleStory3"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="@string/titleWeight"
        android:textStyle="bold"
        android:gravity="center"/>
    <TextView
        android:id="@+id/textViewStory3"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
      android:layout_weight="@string/contentTextViewWeight"/>

<LinearLayout
        android:id="@+id/footerStory3LinearLayout"
        android:layout_weight="@string/footerWeight"
        android:layout_width="fill_parent"
        android:layout_height="0dip">
        <RelativeLayout
            android:id="@+id/footerStory3RelativeLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView
                android:id="@+id/PageCountStory3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="page count"/>

            <TextView
                android:id="@+id/BookmarkTextViewStory3"
                android:layout_width="70sp"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:clickable="true"
                android:gravity="center_vertical"
                android:onClick="addBookmark"
                android:text="bookmark"
                android:textSize="12sp" />

        </RelativeLayout>

</LinearLayout>

ご覧のとおり、テキストビュー「BookmarkTextViewStory3」があり、onClick にメソッド「addBookmark」が接続されています。後で説明するように、そこが行き詰まるところです。

ここに activity_screen_slide.xml があります

私のコードでは、ny FragmentActivityクラス内に「addMookmark」があります(チュートリアルのように、pageadapterインスタンスreationなどの他のコードに加えて)。

/** ユーザーが「ブックマーク ページ/ブックマークの削除」リンクをクリックしたときに呼び出されます */

public void addBookmark(View view) {
            bookmarkPageTextView.setTypeface(null, Typeface.BOLD_ITALIC);}
                        }

テキストビューをクリックしても、テキストビュー(bookmarkPageTextView)への変更は行われません。メソッド addBookmark 内に Toast ステートメントを配置すると、エミュレーターにメッセージがポップアップ表示されます。したがって、コードの実行はメソッド内にあるように見えます。しかし、テキストビューの変更は行われていません。

ここで誰からでも助けてください。

4

1 に答える 1

0

問題が見つかりました。textview オブジェクトへの参照を作成する必要がありました。コードの間違った場所で作成していました。SO行を追加するだけでした

bookmarkPageTextView = (TextView)findViewById(R.id.BookmarkTextViewStory3);

于 2013-04-28T10:11:35.810 に答える