からリストビュー(ユーザーの電子メールと同じ電子メールを含むブロック)にデータを表示する方法ListView
に、自分のメールを使用してfirebaseに格納されたユーザーをログインしているデータを表示したいとします。例えばログインユーザーのメールは[email protected]で、ListView
はブロックブロック内のすべてのアイテムを表示すると、firebaseに格納されているユーザーまたはアイテムの完全な情報を意味します。たとえば、本があると、firebaseにはbookname、content、description、doi、author nameなどが含まれています。著者がログインしている場合、書籍名、説明、内容、およびdoiで表示されます例)。私の問題は、私のリストビューは、それらを含むジョブに関するすべての項目を他のユーザーにも表示しているということです。私は自分の公開ジョブを編集するだけです。だから、これを達成するためにどのfirebaseクエリを書くべきか、ここで私のコードです。firebase
firebase
Javaのクラス
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>
。 誰かが私にこれを手伝ってもらえると大変助かります。ありがとうございました!
//を使用せずにコメントするときに別の行に移動することはできないため、多くのエラーがあると思います。またあなたのWorkActivityは可読ではありません – matrix
それらはコメントでコードではありません –