gpt4 book ai didi

android - 如何从 fragment 发送字符串到类,以更改kotlin中的Json API?

转载 作者:行者123 更新时间:2023-12-02 13:31:36 25 4
gpt4 key购买 nike

当我单击按钮时,我想更改服务中的链接,但这不起作用

我如何从片段发送字符串到类以更改Json API?

这是我的界面

    interface NewsAPI {
@GET
fun getNews(@Url url:String):Single<API>
}

这是我的服务
class NewsAPIService {

private val BASE_URL = "xxxxxxxxxx"
private val api = Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(NewsAPI::class.java)



fun getData():Single<API>{
return api.getNews(CountrySelectFragment().countrCode1)
}
}

这是我的片段
class CountrySelectFragment : Fragment() {
var countrCode1 = ""

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_country_select, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

buttontr.setOnClickListener {
countrCode1 = "trLink"
}

buttonar.setOnClickListener {
countrCode1 = "arLink"

}

buttonuk.setOnClickListener {
countrCode1 = "ukLink"
}

buttonus.setOnClickListener {
countrCode1 = "usaLink"
}
buttonfr.setOnClickListener {
countrCode1 = "frLink"
}


}

}

我该怎么办?

最佳答案

您是否尝试过为所有Button设置OnClick功能?
如果不尝试这个:

 override fun OnClick(view: View){

when (view.id){
R.id.buttontr-> return "trlink"
R.id.button-> return "arlink"
// the rest is the same
}
}

关于android - 如何从 fragment 发送字符串到类,以更改kotlin中的Json API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61157038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com