Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Is using Fragment as an Activity possible in Kotlin

Posted on November 11, 2022 By

Solution 1 :

Fragments have just some different lifecycle methods to be aware of.

enter image description here

If you want to use findViewById for instance you can use it inside onViewCreated.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    view.findViewById(R.id.your_view_id)
}

Problem :

I made fragments in my Kotlin project and now I wanna fill them. But in the .kt file there’s some codes that I didn’t see in activitys. Can I code that .kt file in fragment like I’m coding an activity, or is it gonna make a problem?

Comments

Comment posted by Rohit Jakhar

There are more boiler-plate code in fragment than activity in android studio but you can remove all those code and can have only one or two method.

Comment posted by alpheratz

But when I try to add findViewById or setContentView it’s giving error. Can’t I use them in fragments?

READ  [FIXED] android - Non mandatory method implementation of an interface in Java
Powered by Inline Related Posts
Android Tags:android, android-activity, android-studio, fragment, kotlin

Post navigation

Previous Post: [FIXED] android – How to detect when third party app’s dialog box appears in React native?
Next Post: [FIXED] android – Get the list of user SIM cards and select it – flutter

Related Posts

[FIXED] android – Facebook key hash does not match any stored key hashes – Flutter RELEASE Android
[FIXED] android – Twilio – How to get VideoTracks of the users that are already in a chat room? Android
[FIXED] xamarin.forms – Xamarin Forms Android video (VideoView) black flash on page load or back key + looping Android
[FIXED] android – How to receive daily summary email from firebase analytics? Android
[FIXED] android – (React Native) How to uploading App Signing Key to Google Play Console? Android
[FIXED] javascript – WebSearch API speech recognition not working on Android Mobile Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme