I want to display data in ListView
that logged in user stored in firebase using his mail. e.g. login user's mail is 123@mail.com and the ListView
display all items in block block mean the complete details of user(s) or item(s) stored in firebase. e.g there is a book, firebase contain it's bookname, content, description, doi, author name etc.what i want is that if author is logged in only his book will show with book name, description, content and doi( book reference is just an example). what my problem is that my listview display all items about job including those belongs to other users i want user t just edit his own published jobs. So what firebase query should i write to attain this and here is my code.
firebase
java Class
public class WorkActivity extends AppCompatActivity {
ListView lv;
Button ShowButton;
// Define a String ArrayList for the job
private ArrayList<String> jobdes=new ArrayList<>();
// Define an ArrayAdapter for the list
private ArrayAdapter<String> arrayAdapter;
// Declaring String variable ( In which we are storing firebase serverURL).
public static final String Firebase_Server_URL = "https://jobaps70.firebaseio.com/";
public static final String Firebase_Server_URL1 = "https://jobaps70.firebaseio.com/jobs";
// Declaring String variables to store name & phone number get from EditText.
String PriceHolder, JobDescriptionHolder;
FirebaseHelper helper;
// Declaring Firebase object.
Firebase firebase,firebase1;
// Creating FirebaseAuth.
FirebaseAuth firebaseAuth ;
// Creating FirebaseAuth.
FirebaseUser firebaseUser;
// Creating Boolean variable that holds EditText is empty or not status.
Boolean EditTextStatus ;
TextView ShowDataTextView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work_jobs);
// Actionbar
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(getResources().getColor(R.color.Snow)));
ShowButton = (Button)findViewById(R.id.show);
// Adding MainActivity context into Firebase context.
Firebase.setAndroidContext(WorkActivity.this);
// Passing firebase Server URL into firebase object.
firebase = new Firebase(Firebase_Server_URL);
firebase1=new Firebase(Firebase_Server_URL1);
firebaseAuth = FirebaseAuth.getInstance();
// On activity start check whether there is user previously logged in or not.
if(firebaseAuth.getCurrentUser() == null){
// Finishing current Profile activity.
finish();
// If user already not log in then Redirect to LoginActivity .
Intent intent = new Intent(WorkActivity.this, LoginActivity.class);
startActivity(intent);
// Showing toast message.
Toast.makeText(WorkActivity.this, "Please Log in to continue",
Toast.LENGTH_LONG).show();
}
// Adding firebaseAuth current user info into firebaseUser object.
firebaseUser = firebaseAuth.getCurrentUser();
// Getting logged in user email from firebaseUser.getEmail() method and set into TextView.
setTitle( firebaseUser.getEmail());
setTitleColor(R.color.DarkGray);
firebase.child("jobs");
// Associate the jobs' list with the corresponding ListView
lv = (ListView) findViewById(R.id.lvshow);
// Set the ArrayAdapter to the ListView
arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, jobdes);
lv.setAdapter(arrayAdapter);
// Attach a ChildEventListener to the teacher database, so we can retrieve the job entries
firebase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// Get the value from the DataSnapshot and add it to the jobs' list
JobDetails jo = (JobDetails) dataSnapshot.getValue(JobDetails.class);
String joString = String.valueOf(jo);
arrayAdapter.add(joString);
//
// Notify the ArrayAdapter that there was a change
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError databaseError) {
}
});
}
}
JobDetail
public class JobDetails {
private String price;
private String jobDescription;
private String jobSpinner;
public String email;
public JobDetails() {
// This is default constructor.
}
public String getPrice() {
return price;
}
public void setPrice(String pri) {
this.price = pri;
}
public String getjobDescription() {
return jobDescription;
}
public void setjobDescription(String jobd) {
this.jobDescription = jobd;
}
public void setjob(String jry) {
this.jobSpinner = jry ;
}
public String getjob() {
return jobSpinner;
}
public void setemail(String jel) {
this.email = jel ;
}
public String getemail() {
return email;
}
@Override
public String toString() {
return this.jobSpinner + ": " + this.jobDescription+ ": " +price;
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="com.gumption.zeeshanahmed.jobaps.WorkActivity">
<TextView
android:id="@+id/textdispjobs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_display_jobs"
android:textSize="40sp"
android:textAlignment="center"/>
<ListView
android:id="@+id/lvshow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/show" />
</RelativeLayout>
Currently it is displaying items from other users as well. It would be very helpful if someone could help me with this. Thank you!