我是 Android kotlin 开发的新手。我想在我的应用程序中创建一个选项卡式活动来显示不同的静态 HTML 页面。
我现在可以在我的应用程序中设置 1 个 URL。但是当我更改或点击另一个选项卡时,它会显示类似的视图或 URL。
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.support.v4.app.Fragment
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.webkit.WebView
import xxx.abcabc.xxx.R
import android.util.Log
class PlaceholderFragment : Fragment() {
private lateinit var pageViewModel: PageViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pageViewModel = ViewModelProviders.of(this).get(PageViewModel::class.java).apply {
setIndex(arguments?.getInt(ARG_SECTION_NUMBER) ?: 1)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_left_menu_policies, container, false)
var webTnc: WebView = root.findViewById(R.id.myWebView)
webTnc.loadUrl("https://www.abcxyz.com/abcxyz/abcxyz_webpage/tnc.html")
return root
}
companion object {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private const val ARG_SECTION_NUMBER = "section_number"
/**
* Returns a new instance of this fragment for the given section
* number.
*/
@JvmStatic
fun newInstance(sectionNumber: Int): PlaceholderFragment {
return PlaceholderFragment().apply {
arguments = Bundle().apply {
putInt(ARG_SECTION_NUMBER, sectionNumber)
}
}
}
}
}
如何检测 sectionNumber 之类的东西
if(sectionNumber == 0)
{
var webTnc: WebView = root.findViewById(R.id.myWebView)
webTnc.loadUrl("https://www.abcxyz.com/abcxyz/abcxyz_webpage/tnc.html")
}
else
{
var webTnc: WebView = root.findViewById(R.id.myWebView)
webTnc.loadUrl("https://www.URL2.com/URL2.html")
}
请帮忙。谢谢你。