Well, my question is how can I connect from MainActivity where I have the following selector:
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// SELECCIÓN DEL NAV DRAWER
when (item.itemId) {
R.id.nav_inicio -> {
replaceFragmenty(
fragment = Fragment1(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Incio"
}
R.id.nav_web -> {
replaceFragmenty(
fragment = Fragment2(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Página Web"
}
R.id.nav_proyectos -> {
replaceFragmenty(
fragment = Fragment3(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Proyectos"
}
R.id.nav_comerciate -> {
replaceFragmenty(
fragment = Fragment4(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Comercia-te"
}
R.id.nav_eventos -> {
replaceFragmenty(
fragment = Fragment5(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Eventos"
}
R.id.nav_conocetubarrio -> {
replaceFragmenty(
fragment = Fragment6(),
allowStateLoss = true,
containerViewId = R.id.mainContent
)
title = "Conoce tu barrio"
}
R.id.nav_sobrenosotros -> {
replaceFragmenty(
fragment = SobreNosotros(),
allowStateLoss = false,
containerViewId = R.id.mainContent
)
title = "Sobre Nosotros"
}
R.id.nav_ajustes -> {
replaceFragmenty(
fragment = Fragment8(),
allowStateLoss = false,
containerViewId = R.id.mainContent
)
title = "Ajustes"
}
}
drawer_layout.closeDrawer(GravityCompat.START)
return true
I want to connect in the area of:
R.id.nav_sobrenosotros -> {
replaceFragmenty(
fragment = SobreNosotros(),
allowStateLoss = false,
containerViewId = R.id.mainContent
)
title = "Sobre Nosotros"
}
With an Activity instead of with a Fragment like in the others, where would have all the content that I want to be shown in my application. In About Us, which is an Acivity) would have the following:
@SuppressLint("Registered")
class SobreNosotros : AppCompatActivity() {
internal lateinit var list: ListView
internal lateinit var titleId: Array<String>
internal lateinit var subtitleId: Array<String>
internal var imageId = arrayOf(R.drawable.inicio, R.drawable.web, R.drawable.proyectos, R.drawable.comerciate, R.drawable.conocetubarrio, R.drawable.eventos, R.drawable.ajustes)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.fragment_fragment8)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val actionBar = supportActionBar
if (actionBar != null) {
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setTitle(R.string.title_about)
}
titleId = resources.getStringArray(R.array.title)
subtitleId = resources.getStringArray(R.array.subtitle)
val adapter = AdapterList(this@SobreNosotros, titleId, subtitleId, imageId)
list = this.findViewById(R.id.list)
list.adapter = adapter
list.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
if (position == 4) {
val sendInt = Intent(Intent.ACTION_SEND)
sendInt.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name))
sendInt.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_name) + "\n" + getString(R.string.share_content) + "\n" + "https://play.google.com/store/apps/details?id=" + packageName)
sendInt.type = "text/plain"
startActivity(Intent.createChooser(sendInt, "Comparte"))
}
if (position == 5) {
val appName = packageName
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appName")))
} catch (anfe: android.content.ActivityNotFoundException) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=$appName")))
}
}
if (position == 6) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.more_apps))))
}
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
// app icon in action bar clicked; go home
this.finish()
return true
}
else -> return super.onOptionsItemSelected(item)
}
}
override fun onBackPressed() {
super.onBackPressed()
}
}
That is supposed to show a list of data and so on within my application