I'm creating a welcome page in an another storyboard I also have a skip button that should open the main storyboard

in the main storyboard, there is a minTabbar and every tab has its own navigation bar

here is my code in the acton of the skip button

var window: UIWindow?
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)

@IBAction func skipButton(_ sender: UIButton) {

    let todoTabBar = mainStoryBoard.instantiateViewController(withIdentifier: "mainTabBar") as! UITabBarController
    todoTabBar.selectedIndex = 1
    let nvc = todoTabBar.selectedViewController as? UINavigationController
    nvc?.popToRootViewController(animated: false)
}

but it's not working and nothing happen after tapping on the button, could you help me on that? Thank you so much

If you look at the notes app you can see that the view background isn't flat and that it has a rough like texture and I want to replicate this for an app that I'm working on using SwiftUI but I don't know how I would go about doing so. enter image description here

I am trying to do a leader board(top 3) with sharedPreference. I dont know much about this. when I put b1.setText(Integer.toString(best1)); and when I put n1.setText(nombre1); the score xml doesn`t update with this new values.

This is MainActivity.java what I am trying to do here is saving the input of the user ( the user insert his name in a alertDialog) and saving the score he has made (variable cont)

 public void verificar(View dialogView){
    SharedPreferences sharedPref = getSharedPreferences("PREFS",Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    EditText b = dialogView.findViewById(R.id.userName);
    String name = b.getText().toString();//save the input name
    editor.putInt("lastScore",cont); //insert the score that he made
    editor.putString("lastNombre",name);//insert the name that he made
    editor.apply();
    Intent intent = new Intent(getApplicationContext(),Ranking.class);
    startActivity(intent);


}

This is ranking.java, here I am comparing the score ( cont) with anothers scores (best1,best2,best3) and then I update this scores.

    SharedPreferences preferences = getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    lastScore = preferences.getInt("lastScore" , 0);
    lastNombre = preferences.getString("lastNombre",null);
    best1 = preferences.getInt("best1", 0);
    nombre1 = preferences.getString("nombre1" , null);
    best2 = preferences.getInt("best2", 0);
    nombre1 = preferences.getString("nombre2" , null);
    best3 = preferences.getInt("best3", 0);
    nombre1 = preferences.getString("nombre3" , null);

    if(lastScore > best1 ){
        best1 = lastScore;
        nombre1 = lastNombre;
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("best1" , best1);
        editor.putString("nombre1" , nombre1);
        editor.apply();
        TextView b1 = findViewById(R.id.score1);
        TextView n1 = findViewById(R.id.user1);
        b1.setText(Integer.toString(best1));
        n1.setText(nombre1);
    }

    if(lastScore > best2 ){
        best2 = lastScore;
        nombre2 = lastNombre;
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("best2" , best2);
        editor.putString("nombre2" , nombre1);
        editor.apply();
        TextView b2 = findViewById(R.id.score2);
        TextView n2 = findViewById(R.id.user2);
        b2.setText(Integer.toString(best2));
        n2.setText(nombre2);
    }

    if(lastScore > best3 ){
        best3 = lastScore;
        nombre3 = lastNombre;
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("best3" , best2);
        editor.putString("nombre3" , nombre1);
        editor.apply();
        TextView b3 = findViewById(R.id.score3);
        TextView n3 = findViewById(R.id.user3);
        b3.setText(Integer.toString(best3));
        n3.setText(nombre3);
    }

I'm following this youtube tutorial on created a chat app that connects through P2P. https://www.youtube.com/watch?v=cLpAs_6x1hE&list=PLFh8wpMiEi88SIJ-PnJjDxktry4lgBtN3&index=4

I can't seem to get WIFI_P2P_PEERS_CHANGED_ACTION to change though.

Here's part of my MainActivity:

    wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);

    mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    mChannel = mManager.initialize(this, getMainLooper(), null);

    mReceiver = new WiFiDirectBroadcastReceiver(mManager, mChannel,this);

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
}

WifiP2pManager.PeerListListener peerListListener = new WifiP2pManager.PeerListListener() {
    //THIS PART NEVER GETS CALLED SINCE IT NEVER CHANGES IN THE BROADCAST RECEIVER
};

When I run this, everything works fine

 private void exqListener() {
    btnOnOff.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (wifiManager.isWifiEnabled()) {
                wifiManager.setWifiEnabled(false);
                btnOnOff.setText("On");
            } else {
                wifiManager.setWifiEnabled(true);
                btnOnOff.setText("Off");
            }
        }
    });

    btnDiscover.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {

                @Override
                public void onSuccess() {
                    connectionStatus.setText(("Discovery Started"));
                }

                @Override
                public void onFailure(int i) {
                    connectionStatus.setText(("Discovery Starting Failed"));
                }
            });
        }
    });
}

I put a log in each of the If statements, I see that everything has been triggered but the WIFI_P2P_PEERS_CHANGED_ACTION never changes

 public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
     private WifiP2pManager mManager;
     private WifiP2pManager.Channel mChannel;
     private MainActivity mActivity;

public WiFiDirectBroadcastReceiver (WifiP2pManager mManager, WifiP2pManager.Channel mChannel, MainActivity mActivity) {
    this.mManager = mManager;
    this.mChannel = mChannel;
    this.mActivity = mActivity;
}

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);

        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            Toast.makeText(context, "Wifi is ON", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, "WiFi is OFF", Toast.LENGTH_SHORT).show();
        }
    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
       //never gets called
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        //changes when run
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        //changes when run
    }
}

Here's my android manifest

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

I know I'm missing something but don't know what.

I made two classes(DataBase, and addItem to database class) and one activiy. I dont know how to pass Activity class into method. AndroidStudio throws error. I tried to use getApplicationContext(), but didnt work. Here is code:

DataBase file

   public DataBase(Context context) {
        super(context, DATABASE_NAME, null, TABLE_VERSION); }

DodajNadgranieClass (fragment) file

btZapisz.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                String radiobutton = "", bruttoValue ="", data, tytul;
                                SharedPreferences pref = getSharedPreferences("prefs", MODE_PRIVATE);

                                data = edPodajDate.getText().toString();
                                tytul = edPodajTytul.getText().toString();

                                if (edPodajDate.getText().toString().isEmpty() || edPodajTytul.getText().toString().isEmpty() || radioGroup.getCheckedRadioButtonId() == -1) {
                                    Toast.makeText(DodajNadgranieActivity.this, "Musisz podańá wszystkie dane", Toast.LENGTH_SHORT).show();
                                } else {
                                    if (rbOperetka.isChecked()) {
                                        radiobutton = "1";
                                        bruttoValue = pref.getString("operetka", "");
                                    } else if (rbMusical.isChecked()) {
                                        radiobutton = "2";
                                        bruttoValue = pref.getString("musical", "");
                                    } else if (rbKoncert.isChecked()) {
                                        radiobutton = "3";
                                        bruttoValue = pref.getString("koncert", "");
                                    } else if (rbBajka.isChecked()) {
                                        radiobutton = "4";
                                        bruttoValue = pref.getString("bajka", "");
                                    } else if (rbOpera.isChecked()) {
                                        radiobutton = "5";
                        bruttoValue = pref.getString("opera", "");
                    } else if (rbInne.isChecked()) {
                        radiobutton = "6";
                        bruttoValue = pref.getString("inne", "");
                    }

                    ObliczPodatki obliczPodatki = new ObliczPodatki();
                    obliczPodatki.obliczPodatki(bruttoValue, data, tytul, radiobutton);

                    Toast.makeText(DodajNadgranieActivity.this, "DODANO", Toast.LENGTH_SHORT).show();
                    radioGroup.clearCheck();
                    edPodajTytul.setText(null);
                    edPodajDate.setText(null);

and Activity file

public class ObliczPodatki extends Application {

    public void obliczPodatki (String brutto, String data, String tytul, String radiobutton) {

        kwota_brutto = Double.parseDouble(brutto);
        kwota_netto = kwota_brutto * KWOTA_NETTO;
        kwota_ubezpieczenie_emerytalne = kwota_brutto * UBEZPIECZENIE_EMERYTALNE;
        kwota_ubezpieczenie_rentowe = kwota_brutto * UBEZPIECZENIE_RENTOWE;
        kwota_ubezpieczenie_zdrowotne = kwota_brutto * UBEZPIECZENIE_ZDROWOTNE;
        kwota_ubezpieczenie_chorobowe = kwota_brutto * UBEZPIECZENIE_CHOROBOWE;
        kwota_zaliczka_pit = kwota_brutto * ZALICZKA_PIT;

        sBrutto = "" + kwota_brutto;
        sNetto = "" + kwota_netto;
        sEmerytalne = "" + kwota_ubezpieczenie_emerytalne;
        sRentowe = "" + kwota_ubezpieczenie_rentowe;
        sZdrowotne = "" + kwota_ubezpieczenie_zdrowotne;
        sChorobowe = "" + kwota_ubezpieczenie_chorobowe;
        sPit = "" + kwota_zaliczka_pit;



       DataBase myDb = new DataBase(this);

        myDb.addNewNadgranie(data, tytul, radiobutton, sBrutto, sNetto, sEmerytalne, sRentowe, sZdrowotne, sChorobowe, sPit);
    }
}

I been stuck in this problem for a month now and I really need help guys, I have a custom keyboard homework and I was able to show custom view ( custom layout view ) instead of character and numbers keyboard.. Now I need to inflate activity or fragment Inside this custom layout.. Please I need help to do this,

Note, there is a custom keyboard in Android ( voice type keyboard ) and they are able to show full custom view as a keyboard, any idea about the code base of this?

I am using Room, ViewModel and two-way databinding. In this simple example I need to select data from database and validate it. If data are valid then expose it to databinding. In the other case I have to select other data from database.

DAO:

@Dao
public interface IDAOQuestion {
    @Query("SELECT * FROM Question WHERE questionId = :questionId")
    Question selectQuestion(long qeustionId);
}

Entity:

@Entity
public class Question {
    @NonNull
    @PrimaryKey(autoGenerate = true)
    private long questionId;

    @NonNull
    private MutableLiveData<Integer> correct = new MutableLiveData<>();

    public int getCorrectValue() {
        return correct.getValue() == null ? 0 : correct.getValue();
    }
}

ViewModel

public class QuestionViewModel extends AndroidViewModel {
    public LiveData<Question> mLDQuestion = new MutableLiveData<>();

    public void getQuestion(int questionId) {
        //pseudo DAO access
        Question question = IDAOQuestion.selectQuestion(questionId);

        //here it is always true (question.getCorrectValue() returns 0)
        if(question.getCorrectValue() == 0) {
            getQuestion(questionId + 1);
        } else {
            mLDQuestion.setValue(question);
        }
    }
}

Also I have type converter to convert int from database to LiveData of entity.

public class LiveDataIntegerTypeConverter {

    @TypeConverter
    public static int toInteger(LiveData<Integer> value) {
        if (value == null || value.getValue() == null) {
            return 0;
        } else {
            return value.getValue();
        }
    }

    @TypeConverter
    public static MutableLiveData<Integer> toObservable(int value) {
        MutableLiveData<Integer> liveData = new MutableLiveData<>();
        liveData.postValue(value);
        return liveData;
    }
}

In ViewModel in the function getQuestion I have some "validation". It dowsn't work right. the code question.getCorrectValue() always returns 0. It is because of using MutableLiveData.postValue in TypeConverter and not existing observer on the property.

As workaround I can create another entity (POJO class) without LiveData and use it for validation. After that I can reselect data or map it to "LiveData version" of object. But this seems to be crazy and too complicated. What is the right approach to solve this?

This is just simple example. The logic is just for illustration. I understand why this is happening. Also I can't solve this by changing my SELECT query. Also I have to use the live data on my attributes because I am using it with two way databinding with depending attributes.

Whenever I use any of the other regular simulator iPhones from the 5S - 8+ there are no problems, everything is fine, I touch a button and the action happens. I have an iPhone 7+ and the buttons work fine using the actual device.

But whenever I use the simulator and I choose any of the iPhone X series devices when I touch any button in any view controller I always get a crash

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIBackButtonContainerView titleLabel]: unrecognized selector sent to instance 0x7fdd99c759e0'

whatever this is causes the problem in the X series [_UIBackButtonContainerView titleLabel]

I'm running Xcode in Debug Mode:

enter image description here

What could be the problem?

enter image description here

Code-

lazy var loginButton: UIButton = {
    let button = UIButton(type: .system)
    button.translatesAutoresizingMaskIntoConstraints = false
    button.setTitle("Login", for: .normal)
    button.setTitleColor(UIColor.white, for: .normal)
    button.titleLabel?.font = UIFont(name: "ArialRoundedMTBold", size: 19)
    // I also tried commenting out button.titleLabel?.font = UIFont(name: "ArialRoundedMTBold", size: 19)
    button.backgroundColor = UIColor.lightGray
    button.addTarget(self, action: #selector(loginButtonPressed), for: .touchUpInside)
    button.clipsToBounds = true
    button.layer.cornerRadius = 5
}()

@objc func loginButtonPressed() {
    // do something
}

I'm currently having issues refreshing my collectionview feed using UIRefreshControl. The refresh works fine, however it duplicates the number of cells and continues to append more items to the movieDays array and sort of randomly rearranges the order of the items. I've also tried setting the array to nil each time it refreshes, but then I get a fatal error saying the indexPath is out of range. Does anyway know the correct way to set this up?

Thanks a lot

override func viewDidLoad() {
    super.viewDidLoad()

    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(handleRefresh), for: .valueChanged)

    collectionView.refreshControl = refreshControl
    self.extendedLayoutIncludesOpaqueBars = true

    fetchData()
}

var movieDays: [MoviesByScheduleByDay]? = []

fileprivate func fetchData() {

    let dispatchGroup = DispatchGroup()

    dispatchGroup.enter()
    Service.shared.fetchMoviesBySchedule { (movieDays, err) in
        if let err = err    {
            print("Failed to fetch movies", err)
            return
        }
        self.movieDays = movieDays?.data
        dispatchGroup.leave()
    }

    dispatchGroup.enter()
    Service.shared.fetchFeaturedMovies { (movies, err) in
        if let err = err    {
            print("Failed to fetch featured movies", err)
            return
        }
        self.headerMovies = movies?.data ?? []
        dispatchGroup.leave()
    }

    dispatchGroup.notify(queue: .main) {
        print("complete dispatch")
        self.collectionView.reloadData()
        self.collectionView.refreshControl?.endRefreshing()
    }
}

@objc func handleRefresh()    {
    fetchData()
}

i'm only getting random even number for value 1 . i need it for both value 1 and 2. Can anyone teach me how to solve it?

i'm using threadlocalrandom for it

 public void setQuestion(){
    Random rand = new Random();
    int value1 = ThreadLocalRandom.current().nextInt(10,100);
    int value2 = ThreadLocalRandom.current().nextInt(2,20);

    int randomquestion = rand.nextInt(2);
 if (randomquestion == 1){
        question.setText("What is"+ value1 + "+" + value2 +" ? ");
        expected= "" + (value1 + value2);
    }else if (randomquestion == 2){
        question.setText("What is"+value1 +"-" + value2 +" ? ");
        expected="" + (value1 - value2);
    }else if (randomquestion == 3){
        question.setText("What is"+value1+ "*" + value2 +" ? ");
        expected ="" + (value1*value2);
    }else {
        question.setText("What is"+value1+"/" + value2 +"?");
        expected="" + (value1/value2);
    }
    sumanswer.setText("Total Score ="+ correctanswer +"Correct and"+ wronganswer + "Wrong");
}

i expect it can be in random even number for both value

Im looking for an android c++ ide that I can use on Android with library support I want the ones that let you install any libraries you want and it has to be free as long as I can use any libraries that I want

you can also tell me a way to import libraries on any c++ ide

thats all

As you can see in the screenshot below the two different strings with the same length not drawn with the same width on the canvas. I'm using a monospaced typeface, so isn't it promised to be drawn with the same width? Is that because of the kerning?

Typeface.create(Typeface.MONOSPACE,Typeface.NORMAL)

enter image description here

I am creating a game for android. Each user needs to be authenticated.

Currently, when a new user launches the game, it requests an identification code from my server, and stores it to SharedPreferences. Next time user launches the game, it uses this stored identification code to authenticate. The problem is, when user clears data of this app, there's no way he can get his ID back, so he lost his progress forever.

Is there a way how to generate something like Identification code which is unique and always the same for one player using Firebase Play games auth method?

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                .requestServerAuthCode("MyCID")
                .build();

        mAuth = FirebaseAuth.getInstance();
        super.onCreate(savedInstanceState);
        final FirebaseAuth auth = FirebaseAuth.getInstance();
        AuthCredential credential = PlayGamesAuthProvider.getCredential("MyCID");
        auth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            currentUser = auth.getCurrentUser();
                        } else {
                            Toast.makeText(MainActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
        if (currentUser == null) {
            cu = "NO UID";
        } else {
            cu = currentUser.getUid();
        }

I tried this code (Where is MyCID: I used the CID from the image below), but no Google Play Games pop-up is shown, I get Authentication Failed toast and cu is set to "NO UID".

MyCID

Can someone explain how does this work please?

I've created a CV building app and the last Activity displays all the information in the form of ListViews. Each ListView has layout_height=wrap_content which means that once the user enters more than one previous job, the data falls off the screen and is unscrollable.

I've already tried to limit the space used by the ListView, making it's own data scrollable however this doesn't look right on the screen. I'd much prefer to have all data displayed and the whole screen scrollable. Any suggestions?

Also, I don't want the user to have to move across to other Activities to view the data they've entered.

How to create a notification that displays an entire view in the unlock menu before the user enters their code. As does the basic "Clock" app when an alarm sounds ?

I need to add dependency RESTMock, but I get this error in Gradle.

 project :app > com.github.andrzejchm.RESTMock:android:0.3.3 > com.github.andrzejchm.RESTMock:core:0.3.3 > com.squareup.okhttp3:okhttp-tls:3.13.1

but I use com.squareup.okhttp3:okhttp-tls:3.12.1 in project.

I need version 3.12.1 and RESTMock together, anyway can I have together?

When I upload a picture on the server by okhttp3 or retrofit2 it raises the image but the response is {protocol = h2, code = 200, message =, url = } or not Upload the image from the base and the response is {protocol = h2, code = 422, message = Is it a helper Thank you ......

    private void Registration(){
         final ProgressDialog progress = new ProgressDialog(this);
        progress.setTitle("Uploading");
        progress.setMessage("Please wait...");
        progress.show();

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {

                String content_type  = getMimeType(f.getPath());
                String file_path = f.getAbsolutePath();
                OkHttpClient client = new OkHttpClient();
                RequestBody file_body = RequestBody.create(MediaType.parse(content_type),f);

                RequestBody request_body2 = new MultipartBody.Builder()
                        .setType(MultipartBody.FORM)
//                        .addFormDataPart("name", getText(name))
//                         .addFormDataPart("email", getText(email))
//                        .addFormDataPart("phone", getText(numberPhone))
//                        .addFormDataPart("password", getText(password))
//                        .addFormDataPart("password_confirmation",getText(password))
                        .addFormDataPart("uploaded_file",file_path.substring(file_path.lastIndexOf("/")+1), file_body)
                        .build();
                okhttp3.Request request = new okhttp3.Request.Builder()
                        .url("https://abanob-read.000webhostapp.com/uplode.php")
                          .post(request_body2)
                        .build();

                try {

                    okhttp3.Response response = client.newCall(request).execute();

                    if(!response.isSuccessful()){
                        throw new IOException("Error : "+response);
                    }
                     else {
                         System.out.println("+++++result++++"+response);
                    }
                    progress.dismiss();

                } catch (IOException e) {
                    e.printStackTrace();
                    System.out.println("+++++result+8+++"+e.getLocalizedMessage());
                    System.out.println("+++++result+8+++"+e.getMessage());

                    progress.dismiss();

                }


            }
        });

        t.start();

    }

Will #1 and #2 always produce the same output? What are the advantages of using one solution over the other one?

Solution #2 looks cleaner and simpler to me, is it faster also?

    //#1
    val gson = Gson()
    val j = JsonObject() //com.google.gson
    j.add("foo", gson.fromJson(getBar(), JsonElement::class.java))
    val jString = gson.toJson(j)
    Log.d(TAG,jString)

    //#2
    val j1 = JSONObject() //org.json
    j1.put("foo", getBar())
    val jString1 = j1.toString()
    Log.d(TAG,jString1)


    fun getBar() : String {
        //do stuff and return a string
    }

Thanks in advance

I try to retrieve data from firebase and setText to TextViews, but it does not work. I tried different methods. I get no error, the strings are not null, but the text does not display. I used these methods and in another projects and they worked. What am I doing wrong?

Here is the code:

drawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View headerView = navigationView.getHeaderView(0);
    navUsername = headerView.findViewById(R.id.navUsername);
    navEmail = headerView.findViewById(R.id.navEmail);

    ActionBarDrawerToggle toogle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawerLayout.addDrawerListener(toogle);
    toogle.setDrawerIndicatorEnabled(true);
    toogle.syncState();
    if(savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                new ArtFragment()).commit();
        navigationView.setCheckedItem(R.id.nav_art);
    }

    auth = FirebaseAuth.getInstance();
    currentUser = auth.getCurrentUser();
    String uid = currentUser.getUid();

    refUsername = FirebaseDatabase.getInstance().getReference().child("users").child(uid);

    refUsername.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {

                User user = dataSnapshot.getValue(User.class);

                navUsername.setText(user.getUsername());
                navEmail.setText(user.getEmail());


                }

            }



        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
        }
    });
}

Firebase json example:

users
   uid
     email: ""
     password:""
     username:""

This is User.class:

public class User {
String username, email, password;

public User(String username, String email, String password){
    this.username = username;
    this.email = email;
    this.password = password;
}
public User(){}

public void setUsername(){
    this.username = username;
}
public String getUsername(){
    return username;
}
public void setEmail(){
    this.email = email;
}
public String getEmail(){
    return email;
}
public void setPassword(){
    this.password = password;
}
public String getPassword(){
    return password;
}

}

Why OnClicklistener not working inside CollapsingToolbarLayout?

i use:

compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:design:27.0.0'
compile 'com.android.support:support-v4:27.0.0'

My Layout:

<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:fitsSystemWindows="true"
    tools:context="com.mkurbanov.lebap_kwartira.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="256dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/header_slider"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:autofillHints="true"
                android:background="@color/colorPrimary"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>


    <include layout="@layout/content_dug" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_share_black_48dp"
        android:tint="@color/colorPrimary"
        app:backgroundTint="@color/white"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:rippleColor="@color/colorPrimary" />

    <Button
        android:id="@+id/button_call"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom|center"
        android:layout_margin="10dp"
        android:background="@drawable/btn_empty_solid"
        android:foreground="?attr/selectableItemBackground"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="@string/call"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/white"
        android:textSize="@dimen/text_size" />

</android.support.design.widget.CoordinatorLayout>

Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words. Some Words.

I am working with navigation component and bottom navigation

val navController = indNavController(R.id.nav_host_fragment)
bottom_navigation.inflateMenu(R.menu.bottom_navigation_menu)
bottom_navigation.setupWithNavController(navController)

and I am facing the next issue:

When an item is selected in the bottom navigation, then a fragment is loaded. The problem comes when I press again the same item, then a new fragment will be loaded, which it does not make sense at all.

Example: 1- User selects menu item A, then FragmentA is loaded. 2- User selects again menu item A, then a new FragmentA will be loaded,

I was trying to use

bottom_navigation.setOnNavigationItemSelectedListener {  }

But then the bottom navigation will not work with the navController.

So the question is: there is a way to handle this situation in order to load again a new fragment when the user is in that screen already?