我試圖爲書籍應用程序製作viewpager。我從android turorial http://developer.android.com/training/animation/screen-slide.html獲得了幫助,其餘的我都試圖自己做。我被困在視圖更改(單擊時更改textview文本字體)在頁面內不起作用的地方。無法對viewpager中的視圖進行更改
這裏的一些代碼
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>
,你可以看到有TextView的 「BookmarkTextViewStory3」 裏有一個方法「收藏本站「附加onClick。這就是我陷入困境,因爲我稍後會解釋。
這裏是我的代碼activity_screen_slide.xml
我有「addMookmark」紐約FragmentActivity類中(除了用於pageadapter例如reation等作爲教程中的其他代碼)。
/**當用戶點擊了被稱爲 「書籤頁/刪除書籤」 鏈接*/
public void addBookmark(View view) {
bookmarkPageTextView.setTypeface(null, Typeface.BOLD_ITALIC);}
}
到的TextView(bookmarkPageTextView)的變化,當我點擊的TextView不會發生。如果我在方法addBookmark中添加Toast語句,則可以在仿真器上看到彈出的消息。因此代碼執行似乎進入方法。但textview的變化沒有發生。
任何人的幫助。