android - 将 TextView 插入 Firebase
问题描述
如何将 TextView 的文本放入 Firebase 数据库?
“计数”是 TextView。
也许错误是“String dt=txtdistance.getText().toString();”
//Insert Data to Firebase
txtlocation= findViewById(R.id.search);
txtdistance=findViewById(R.id.count);
bt=(Button)findViewById(R.id.button);
mDatabase=FirebaseDatabase.getInstance();
ref=mDatabase.getReference().child("location");
Button bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String lc=txtlocation.getText().toString();
String dt=txtdistance.getText().toString();
DatabaseReference mRef=ref;
mRef.child("location").setValue(lc);
mRef.child("distance").setValue(dt);
startActivity(new Intent(Dashboard.this, Filter.class));
}
});
解决方案
@George Sepetadelis 这是我所有的Dasboard
代码。
public class Dashboard extends AppCompatActivity {
private TextView count;
private SeekBar seek_Bar;
Button bt;
EditText txtlocation, txtdistance;
DatabaseReference ref;
FirebaseDatabase mDatabase;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//seekbar
count = findViewById(R.id.count);
seek_Bar = findViewById(R.id.seekBar);
seek_Bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int i = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
i = progress;
count.setText(""+i+" χλμ");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//Insert Data to Firebase
txtlocation= findViewById(R.id.search);
txtdistance=findViewById(R.id.count);
bt=(Button)findViewById(R.id.button);
mDatabase=FirebaseDatabase.getInstance();
ref=mDatabase.getReference().child("location");
Button bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String lc=txtlocation.getText().toString();
String dt=txtdistance.getText().toString();
ref.child("location").setValue(lc);
ref.child("distance").setValue(dt);
startActivity(new Intent(Dashboard.this, Filter.class));
}
});
}
}
推荐阅读
- python - Pandas Dataframe 无法定位具有不同数据类型的列
- c - 尝试从用户输入的数组中获取最小数字时出现分段错误
- sql-server - 获取 Datagridview 组合框中所选项目的 ID 并显示取决于 Selectedvalue 的表单
- python - 如何反向批量标准化
- android - android 是否加密通过 HttpConnection Post 或 Retrofit 等库发送的 https 标头?
- javascript - C3JS 条形图,带有颜色的特定顺序
- angular - Angular 7 EventSource 无限期地获取流
- jquery - XNAT JSON 获取项目 ID 列表以填充下拉列表以供选择
- python - 是否可以创建数组数组的 numpy.memmap?
- haskell - 似乎不能在实例声明中使用带有类型变量的类型表达式和需要显式类型的函数