Alon Shlider
Alon Shlider

Reputation: 1318

fragment won't start ontop of activity

I have the following code -

class StartupActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_startup)

        continueButton.setOnClickListener(this)
        termsAndService.setOnClickListener(this)
        privacyPolicy.setOnClickListener(this)

    }

    override fun onClick(view: View?) {
        when (view?.id) {
            R.id.activity_startup_terms_and_service and R.id.activity_startup_privacy_policy -> {
                supportFragmentManager.beginTransaction()
                    .replace(R.id.activity_startup_root_layout, TermsAndConditionsFragment())
                    .addToBackStack("")
                    .commit()
            }
        }
    }
}

and the following XML -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:orientation="vertical"
    android:id="@+id/activity_startup_root_layout"
    tools:context=".StartupActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:src="@drawable/home_logo" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <ImageView
        android:id="@+id/activity_startup_twoverte_logo"
        android:layout_width="100dp"
        android:layout_height="20dp"
        android:layout_gravity="center"
        android:layout_marginTop="100dp"
        android:src="@drawable/twoverte_logo" />

    <TextView
        android:id="@+id/activity_startup_welcome_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/main_app_top_margin_15dp"
        android:fontFamily="@font/roboto_light"
        android:text="@string/activity_startup_welcome_text"
        android:textColor="@android:color/darker_gray"
        android:textSize="16sp" />

    <Button
        android:id="@+id/activity_startup_agree_and_continue_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginTop="@dimen/main_app_top_margin_15dp"
        android:layout_marginEnd="28dp"
        android:background="@drawable/activity_startup_rounded_button"
        android:fontFamily="@font/roboto_light"
        android:text="@string/activity_startup_agree_and_Continue"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="16sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="28dp"
        android:layout_marginTop="@dimen/main_app_top_margin_15dp"
        android:layout_marginEnd="28dp"
        android:fontFamily="@font/roboto_light"
        android:gravity="start"
        android:text="@string/activity_startup_terms_and_conditions"
        android:textColor="@android:color/darker_gray"
        android:textSize="12sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginEnd="28dp"
        android:layout_marginBottom="30dp"
        android:gravity="start"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/activity_startup_terms_and_service"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/roboto_light"
            android:text="@string/activity_startup_terms_of_service"
            android:textColor="@color/white"
            android:textSize="12sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:fontFamily="@font/roboto_light"
            android:text="@string/activity_startup_and"
            android:textColor="@android:color/darker_gray"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/activity_startup_privacy_policy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:fontFamily="@font/roboto_light"
            android:text="@string/activity_startup_privacy_policy"
            android:textColor="@color/white"
            android:textSize="12sp" />


    </LinearLayout>


</LinearLayout>

Why wouldn't the fragment activate? I can't get it to recognize the click

I tried to add the click listeners directly to the textviews and it did not help them recognize clicks.

I tried to add "clickable" and "focusable" attributes in the XML and it did not help either.

What am I missing?

Upvotes: 0

Views: 24

Answers (1)

Yann Huissoud
Yann Huissoud

Reputation: 1033

Change

R.id.activity_startup_terms_and_service and R.id.activity_startup_privacy_policy

to

R.id.activity_startup_terms_and_service, R.id.activity_startup_privacy_policy

Upvotes: 1

Related Questions