Java Firebase表格标题在哪里定义?
这个比较容易。我正在搜索确切定义tabletitle的位置。 就像 “post_05”:{ “-LjaxpXonCsmzIrdR89M”:{ “说明”:“5.贝施雷邦”, “图像”:“http”, “成员”:“5.职位”, “名称”:“5.贝施雷邦”, “状态”:“在线”, “时间戳”:1562948098382, “职务”:“5.职务” }} 或 “-LjaxpXonCsmzIrdR89M”:{ “说明”:“5.贝施雷邦”, “图像”:“http”, “成员”:“5.职位”, “名称”:“5.贝施雷邦”, “状态”:“在线”, “时间戳”:1562948098382, “职务”:“5.职务” } 但我想要的是: “post_05”:{ “说明”:“5.贝施雷邦”, “图像”:“http”, “成员”:“5.职位”, “名称”:“5.贝施雷邦”, “状态”:“在线”, “时间戳”:1562948098382, “职务”:“5.职务” } 所以我的问题是,如何停止这种自动创建 谢谢Java Firebase表格标题在哪里定义?,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,这个比较容易。我正在搜索确切定义tabletitle的位置。 就像 “post_05”:{ “-LjaxpXonCsmzIrdR89M”:{ “说明”:“5.贝施雷邦”, “图像”:“http”, “成员”:“5.职位”, “名称”:“5.贝施雷邦”, “状态”:“在线”, “时间戳”:1562948098382, “职务”:“5.职务” }} 或 “-LjaxpXonCsmzIrdR89M”:{ “说明”:“5.贝施雷邦”, “图像”:“http”, “成员”:“5.职位”, “名称”:“5.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.posts_newpost_activity);
btnCreate = (Button) findViewById(R.id.new_post_btn);
etTitle = (EditText) findViewById(R.id.new_post_title);
etImage = (EditText) findViewById(R.id.new_post_image);
etDescription = (EditText) findViewById(R.id.new_post_description);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
FirebaseUser mFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (mFirebaseUser != null)
{
currentUserID = mFirebaseUser.getUid();
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
DBRef = FirebaseDatabase.getInstance().getReference();
}
// Read from the USER database
fAuth = FirebaseAuth.getInstance();
btnCreate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DBRef.addValueEventListener(new ValueEventListener()
{
public void onDataChange(DataSnapshot dataSnapshot) {
//currentGroupID = dataSnapshot.child("group_1").getValue().toString();
currentGroupID = dataSnapshot.child("Users").child(currentUserID).child("group_1").getValue().toString();
size = (int) dataSnapshot.child("post_list").child(currentGroupID).getChildrenCount();
/*
try
{
//postID = getIntent().getStringExtra("noteId");
post_count = size+1;
String text = (post_count < 10 ? "0" : "") + post_count;
postID = "post_"+text;
//Toast.makeText(this, noteID, Toast.LENGTH_SHORT).show();
if (!postID.trim().equals("")) {
isExist = true;
} else {
isExist = false;
}
} catch (Exception e) {
e.printStackTrace();
}
UserInformation user_i = new UserInformation();
user_i.setGroupId(currentGroupID);
user_i.setpostID(postID);
putData(user_i);
//getGroupID(currentGroupID);
*/
}
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("New Tag", "Failed to read value.", error.toException());
}
});
String title = etTitle.getText().toString().trim();
String image = etImage.getText().toString().trim();
String description = etDescription.getText().toString().trim();
final String groupId = currentGroupID;
Log.w("New Tag", "Ln 143 currentGruppID: "+currentGroupID);
Log.w("New Tag", "Ln 144 currentPostID: "+postID);
if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(description)) {createPost(title, description, groupId, image, postID);}
else {Snackbar.make(view, "Fill empty fields", Snackbar.LENGTH_SHORT).show();}
}
});
if(mFirebaseUser != null)
{
// Read from the database
DBRef.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
currentGroupID = dataSnapshot.child("Users").child(currentUserID).child("group_1").getValue().toString();
size = (int) dataSnapshot.child("post_list").child(currentGroupID).getChildrenCount();
post_count = size+1;
String text = (post_count < 10 ? "0" : "") + post_count;
postID = "post_"+text;
UserInformation user_group = new UserInformation();
user_group.setGroupId(currentGroupID);
UserInformation user_key = new UserInformation();
user_key.setpostID(postID);
Log.d("New Tag", "onCreate()Ln 171 GroupID is: " + currentGroupID);
Log.d("New Tag", "onCreate()Ln 171 postID is: " + postID);
putData(user_group, user_key);
}
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("New Tag", "Failed to read value.", error.toException());
}
});
}
}
private void putData(UserInformation user_group, UserInformation user_key)
{
final String groupId = user_group.getGroupId();
final String postID = user_key.getpostID();
Log.w("New Tag", "puData() 189 is the currentGruppID: "+groupId);
Log.w("New Tag", "puData() 189 is the currentPostID: "+postID);
fPostsDatabase = FirebaseDatabase.getInstance().getReference().child("post_list").child(groupId);
if (isExist)
{
fPostsDatabase.child(postID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
if (dataSnapshot.hasChild("title") && dataSnapshot.hasChild("description")) {
//postID = "post_" + post_count;
Log.w("New Tag", "The post-Count is: " + post_count);
String title = dataSnapshot.child("title").getValue().toString();
Toast.makeText(posts_newPost_Activity.this, "Post Details" + postID, Toast.LENGTH_SHORT).show();
String description = dataSnapshot.child("description").getValue().toString();
String status = dataSnapshot.child("status").getValue().toString();
String name = dataSnapshot.child("name").getValue().toString();
String image = dataSnapshot.child("image").getValue().toString();
if (isExist) {
etTitle.setText(title);
etDescription.setText(description);
//etStatus.setText(status);
//etName.setText(name);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(posts_newPost_Activity.this, "Database Error Ln 206", Toast.LENGTH_SHORT).show();
}
});
}
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.posts\u newpost\u活动);
btnCreate=(按钮)findViewById(R.id.new\u post\u btn);
etTitle=(编辑文本)findViewById(R.id.new\u post\u标题);
etImage=(EditText)findViewById(R.id.new\u post\u image);
etDescription=(EditText)findViewById(R.id.new\u post\u description);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
FirebaseUser mFirebaseUser=FirebaseAuth.getInstance().getCurrentUser();
if(mFirebaseUser!=null)
{
currentUserID=mFirebaseUser.getUid();
UsersRef=FirebaseDatabase.getInstance().getReference().child(“用户”).child(当前用户ID);
UsersRef=FirebaseDatabase.getInstance().getReference().child(“用户”).child(当前用户ID);
DBRef=FirebaseDatabase.getInstance().getReference();
}
//从用户数据库中读取
fAuth=FirebaseAuth.getInstance();
btnCreate.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
DBRef.addValueEventListener(新的ValueEventListener()
{
公共void onDataChange(DataSnapshot DataSnapshot){
//currentGroupID=dataSnapshot.child(“group_1”).getValue().toString();
currentGroupID=dataSnapshot.child(“用户”).child(currentUserID).child(“组1”).getValue().toString();
size=(int)dataSnapshot.child(“post_list”).child(currentGroupID).getChildrenCount();
/*
尝试
{
//postID=getIntent().getStringExtra(“noteId”);
post_计数=大小+1;
字符串文本=(post_计数<10?“0”:“”)+post_计数;
posted=“post_u2;”+文本;
//Toast.makeText(this,noteID,Toast.LENGTH_SHORT).show();
如果(!postID.trim()等于(“”){
isExist=真;
}否则{
isExist=假;
}
}捕获(例外e){
e、 printStackTrace();
}
UserInformation user_i=新用户信息();
用户设置组ID(当前组ID);
用户i.setpostID(postID);
putData(用户i);
//getGroupID(currentGroupID);
*/
}
已取消的公共无效(DatabaseError错误){
//无法读取值
Log.w(“新标记”,“读取值失败”,error.toException());
}
});
字符串title=etTitle.getText().toString().trim();
字符串image=etImage.getText().toString().trim();
String description=etDescription.getText().toString().trim();
最终字符串groupId=currentGroupID;
Log.w(“新标签”,“LN143 currentGrupId:+currentGroupID”);
Log.w(“新标签”,“Ln 144 currentPostID:+postID”);
如果(!TextUtils.isEmpty(title)和&!TextUtils.isEmpty(description)){createPost(title,description,groupId,image,postID);}
else{Snackbar.make(视图,“填充空字段”,Snackbar.LENGTH_SHORT.show();}
}
});
if(mFirebaseUser!=null)
{
//从数据库中读取
DBRef.addValueEventListener(新的ValueEventListener(){
公共void onDataChange(DataSnapshot DataSnapshot){
currentGroupID=dataSnapshot.child(“用户”).child(currentUserID).child(“组1”).getValue().toString();
size=(int)dataSnapshot.child(“post_list”).child(currentGroupID).getChildrenCount();
post_计数=大小+1;
字符串文本=(post_计数<10?“0”:“”)+post_计数;
posted=“post_u2;”+文本;
UserInformation user_group=new UserInformation();
用户组setGroupId(currentGroupID);
UserInformation user_key=newuserinformation();
用户密钥setpostID(postID);
Log.d(“新标记”,“onCreate()Ln 171 GroupID为:”+currentGroupID);
Log.d(“新标签”,“onCreate()Ln 171 postID为:”+postID);
putData(用户组、用户密钥);
}
已取消的公共无效(DatabaseError错误){
//无法读取值
Log.w(“新标记”,“读取值失败”,error.toException());
}
});
}
}
私有无效putData(用户信息用户组,用户信息用户密钥)
{
最后一个字符串groupId=user_group.getGroupId();
private void createPost(String title, String description, String group_id, String image, String key) {
final String groupId = group_id;
Log.d("New Tag", "GROUPiD Ln 253 is: " + groupId);
UserInformation user_key = new UserInformation();
postID = key;
Log.d("New Tag", "postID Ln 253 is: " + postID);
Log.d("New Tag", "postID Ln 253 is: " + postID);
fConDatabase = FirebaseDatabase.getInstance().getReference().child("Connection").child(groupId).child("posts");
fPostsDatabase = FirebaseDatabase.getInstance().getReference().child("post_list").child(groupId);
if (fAuth.getCurrentUser() != null) {
if (isExist) {
// UPDATE A Post
Map updateMap = new HashMap();
updateMap.put("title", etTitle.getText().toString().trim());
updateMap.put("description", etDescription.getText().toString().trim());
updateMap.put("name", etTitle.getText().toString().trim());
updateMap.put("timestamp", -1 * new Date().getTime());
updateMap.put("image", etImage.getText().toString().trim());
updateMap.put("status", "Online");
fPostsDatabase.child(postID).updateChildren(updateMap);
fConDatabase.child(postID).updateChildren(updateMap);
Toast.makeText(this, "Post updated (UPDATE).", Toast.LENGTH_SHORT).show();
} else {
// CREATE A NEW Post
final DatabaseReference newPostRef = fPostsDatabase.push();
final DatabaseReference newPostCon = fConDatabase.push();
final Map postMap = new HashMap();
postMap.put("title", title);
postMap.put("description", description);
postMap.put("name", description );
postMap.put("image", image);
postMap.put("status", "Online");
postMap.put("member", title);
postMap.put("timestamp", ServerValue.TIMESTAMP);
final Map postMap2 = new HashMap();
postMap2.put("Posts", "Saved");
Thread mainThread = new Thread(new Runnable() {
@Override
public void run() {
newPostRef.setValue(postMap).addOnCompleteListener(new OnCompleteListener<Void>() {
Thread mainThread2 = new Thread(new Runnable() {
@Override
public void run() {
newPostCon.setValue(postMap2).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(posts_newPost_Activity.this, "Post added to database1", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(posts_newPost_Activity.this, "ERROR: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
});
//ENDE 2ter aufruf
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(posts_newPost_Activity.this, "Post added to database2", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(posts_newPost_Activity.this, "ERROR: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
mainThread2.start();
}
});
}
});
mainThread.start();
}
} else {Toast.makeText(this, "USERS IS NOT SIGNED IN", Toast.LENGTH_SHORT).show();}
}
final DatabaseReference newPostRef = fPostsDatabase;