Thursday , October 21 2021

Firebase Realtime Database CRUD Operation for Android – Android Coding by DMTechnolab

The package The trap.Simplified coding.firebasedatabaseexample;

Import Android.Content.Intent;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.The.Bundle;

Import Android.The text.Textulates;

Import Android.Opinion.Opinion;

Import Android.Widget.switch;

Import Android.Widget.Change in writing;

Import Android.Widget.list View;

Import Android.Widget.Seek bar;

Import Android.Widget.text view;

Import Android.Widget.Toast;

Import With.Google.Fire.The database.DataSnapshot;

Import With.Google.Fire.The database.Database error;

Import With.Google.Fire.The database.DatabaseReference;

Import With.Google.Fire.The database.FirebaseDatabase;

Import With.Google.Fire.The database.ValueEventListener;

Import Java.Useful.array list;

Import Java.Useful.The list;

public class Artist Is spread AppCompatActivity {{

switch buttonAddTrack;

Change in writing editTextTrackName;

Seek bar Is looking for;

text view textViewRating, textViewArtist;

list View listViewTracks;

DatabaseReference Database track;

The list The tracks;

@Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.Activity_factor);

Intent is intended = Get());

/ *

* This line is important

* This time we are not getting direct node reference

* But inside node track we are creating a new child with artist id

* And inside that node we will store all the tracks with unique id

* * /

Database track = FirebaseDatabase.get Instance()).refer to()“Track”).child()is intended.getStringExtra()Main activity.ARTIST_ID));

buttonAddTrack = ()switch) findViewById()R.Id.buttonAddTrack);

editTextTrackName = ()Change in writing) findViewById()R.Id.editTextName);

Is looking for = ()Seek bar) findViewById()R.Id.Is looking for);

textViewRating = ()text view) findViewById()R.Id.textViewRating);

textViewArtist = ()text view) findViewById()R.Id.textViewArtist);

listViewTracks = ()list View) findViewById()R.Id.listViewTracks);

The tracks = New array list());

textViewArtist.Settext()is intended.getStringExtra()Main activity.artist name));

Is looking for.setOnSeekBarChangeListener()New Seek bar.OnSeekBarChangeListener()) {{

@Override

public Zero onProgressChanged()Seek bar Seek bar, int I am, Boolean B) {{

textViewRating.Settext()String.Value of()I am));

}

@Override

public Zero onStartTrackingTouch()Seek bar Seek bar) {{

}

@Override

public Zero onStopTrackingTouch()Seek bar Seek bar) {{

}

});

buttonAddTrack.setOnClickListener()New Opinion.OnClickListener()) {{

@Override

public Zero on click()Opinion Opinion) {{

saveTrack());

}

});

}

@Override

Protected Zero onStart()) {{

Super.onStart());

Database track.addValueEventListener()New ValueEventListener()) {{

@Override

public Zero onDataChange()DataSnapshot dataSnapshot) {{

The tracks.Clear());

For ()DataSnapshot PostSnapshot : dataSnapshot.getChildren())) {{

Track Track = PostSnapshot.getValue()Track.class);

The tracks.Add up()Track);

}

Track list trackListAdapter = New Track list()Artist.this, The tracks);

listViewTracks.setAdapter()trackListAdapter);

}

@Override

public Zero Turned on()Database error Database error) {{

}

});

}

Private Zero saveTrack()) {{

String trackName = editTextTrackName.Gettext()).Wire()).Trim());

int Rating = Is looking for.getProgress());

If ()!Textulates.Is Empty()trackName)) {{

String Id = Database track.Push it()).Give the key());

Track Track = New Track()Id, trackName, Rating);

Database track.child()Id).To value()Track);

Toast.Makeup()this, “Track saved”, Toast.LENGTH_LONG).Display());

editTextTrackName.Settext()“”);

} other {{

Toast.Makeup()this, “Please enter a name”, Toast.LENGTH_LONG).Display());

}

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

One comment

  1. Hey! Do you know if they make any plugins to protect against hackers?

    I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *