это мой макет -> frag_three.xml
<ScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/supportback">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//some Textviews here...
<Button
android:id="@+id/sendButton"
android:layout_width="58dp"
android:layout_height="51dp"
android:layout_gravity="right"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:clickable="true"
android:background="@drawable/send_email"/>
</LinearLayout>
</ScrollView>
, и это мой фрагмент:
class fragmentC : Fragment() {
companion object {
fun newInstance():Fragment {
var fb :fragmentC = fragmentC()
return fb
}}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_three,container,false)
val btn = rootView.findViewById(R.id.sendButton) as Button
btn.setOnClickListener {
Toast.makeText(context,"test",Toast.LENGTH_LONG).show()
}
return rootView
}}
без ошибок, без исключений, ничего плохого в logcat.Я не смог найти проблему, какая-нибудь помощь, пожалуйста?
edit1
это макет, в котором должен работать фрагмент:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
android:id="@+id/activity_main">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:animateLayoutChanges="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#389486"
app:menu="@menu/bottom_view">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
PS: есть еще два фрагмента, но сейчас они пустые, я их еще не трогал
edit2 основной класс активности
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navigation.setOnNavigationItemSelectedListener (object : BottomNavigationView.OnNavigationItemSelectedListener{
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when(item.itemId){
R.id.bot_list ->{
drawerLayout.openDrawer(Gravity.START)
}
R.id.bot_home ->{
var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
ft.replace(R.id.frame_layout,fragmentA.newInstance())
ft.commit()
}
R.id.bot_cart ->{
var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
ft.replace(R.id.frame_layout,fragmentB.newInstance())
ft.commit() }
R.id.bot_message ->{
//here is the required fragment
var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
ft.replace(R.id.frame_layout,fragmentC.newInstance())
ft.commit() }
}
return true
}
})
var ft : FragmentTransaction = supportFragmentManager.beginTransaction()
ft.replace(R.id.frame_layout,fragmentA.newInstance())
ft.commit()
}
}