iT邦幫忙

0

android java 一問

想問一下大家, 如何可以從app mainactivity class裡把自定義的array

private static String[] captionlist = {"fukme", "fukyou", "fukher"};

傳到library 的一個class 裡.

舜~ iT邦高手 1 級 ‧ 2019-11-28 13:46:24 檢舉
您想問的是不同物件間的資料傳遞??
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
舜~
iT邦高手 1 級 ‧ 2019-11-28 13:50:52

您想問的是不同物件間的資料傳遞??

在該library的class中加入(或已經存在)特定參數的function~~
比如說 public MyFunc(String[] arr)

在您的app mainactivity class中,初始畫該library的class,並把您的captionlist 丟到特定接收參數的某個方法中
xxx.MyFunc(captionlist );

看更多先前的回應...收起先前的回應...
diu7me iT邦新手 4 級 ‧ 2019-11-28 13:57:51 檢舉

我在content_main.xml 裡的code

`
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.asura.posterslider.MainActivity"
tools:showIn="@layout/activity_main">

<com.asura.library.views.PosterSlider
    android:id="@+id/poster_slider"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginTop="0dp"
    app:defaultIndicator="circle"
    app:hideIndicators="false"
    app:imageSlideInterval="5000"
    app:layout_constraintTop_toTopOf="parent"
    app:loopSlides="true" />

</android.support.constraint.ConstraintLayout>`

有沒有辦法可以直接在mainactivity裡check 到這個posterslider 轉slide了, 就是說有沒有一些listener 可以收到.

舜~ iT邦高手 1 級 ‧ 2019-11-28 15:45:07 檢舉

android:id="@+id/XXX"
您可以給id後,直接在java內處理~~~
ex.
Button myBtn = (Button)findViewById(R.id.my_btn_id);

diu7me iT邦新手 4 級 ‧ 2019-11-28 16:04:17 檢舉

我不是說button , 我的意思是說如何detect這個posterslide的auto slide的變動, 而不是button按之後.

GHH iT邦新手 1 級 ‧ 2019-11-28 18:16:07 檢舉

那就寫在你這個 library class 的 slide 方法裡呀

我要發表回答

立即登入回答