我如何在Stepper布局适配器中动态分段

时间:2018-10-08 23:46:10

标签: java android kotlin stepper

我正在使用https://github.com/stepstone-tech/android-material-stepper中的com.stepstone.stepper:material-stepper:4.3.1

我有一个问题。 我想使用此库在我的android应用程序中执行表单查询器。 我请求在服务器端启动服务 我已经按照该库的github页面中的教程和步骤进行操作。

这是我的代码:

class SesiWawancaraAdapter(fm : FragmentManager, context : Context) : AbstractFragmentStepAdapter(fm, context) {

    private var mDaftarQuisioner : MutableList<ListPertanyaan>  = arrayListOf()

    override fun createStep(position: Int): Step? {
        when(position) {
            0 -> SesiWawancaraStepper("this is Variable Page 1",null)
            1 -> SesiWawancaraStepper("this is Variable Page 2",null)
            2 -> SesiWawancaraStepper("this is Variable Page 3",null)
            else -> {
                throw IllegalArgumentException("Unsupported position: " + position)
            }
        }
        return null
    }

    override fun getCount(): Int {
        return 3
    }

    override fun getViewModel(@IntRange(from = 0) position: Int): StepViewModel {
        //Override this method to set Step title for the Tabs, not necessary for other stepper types
        return StepViewModel.Builder(context)
                .setTitle(R.string.app_name) //can be a CharSequence instead
                .create()
    }


}

现在我想填写适配器上的可变变量,以便可以从服务器的json响应中的json格式生成片段中的数据。像这样的json示例:

[
{"title","contentText"},
{"title","contentText"},
{"title","contentText"},
{"title","contentText"}
]

我有这样的片段

@SuppressLint("ValidFragment")
class SesiWawancaraStepper(private var mPetujukSoal : String?, private var mPertanyaan : String?, private var mJawaban : JSONObject?) : Fragment(), Step {

    private lateinit var v : View
    private lateinit var petunjuksoal : TextView
    private lateinit var pertanyaansoal : TextView

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        v = inflater.inflate(R.layout.fragment_feature_survey_sesiwawancara_stepper, container, false)
        petunjuksoal = v.findViewById(R.id.petunjuksoal)
        pertanyaansoal = v.findViewById(R.id.pertanyaan)
        petunjuksoal.text = mPetujukSoal
        pertanyaansoal.text = mPertanyaan
        return v
    }

    override fun onSelected() {

    }

    override fun verifyStep(): VerificationError? {
        return null
    }

    override fun onError(error: VerificationError) {

    }

}

0 个答案:

没有答案