Java code
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.ValueEventListener;
import java.text.CollationElementIterator;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference();
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// // This method is called once with the initial value and again
// // whenever data at this location is updated.
Object value = dataSnapshot.getValue(Object.class);
textview1.setText.value.toString();
}
@Override
public void onCancelled(DatabaseError error) {
// // Failed to read value
}
});
}
}
xml code
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test" />
This is an error in the code textview1.setText.value.toString(); Is there an error in resource association?ㅠ<
android-studio
textview1 = (TextView) findViewById(R.id.textview1);
Where is....
© 2024 OneMinuteCode. All rights reserved.