我想在databasereference
活动中调用Firebase.java
活动的showFullList.java
变量,该怎么做?我必须使用RecyclerView
在此活动中显示从firebase检索到的列表。请帮忙。代码在这里。
Firebase.java
公共类Firebase扩展了AppCompatActivity {
EditText EDname;
Button addB;
Spinner choose;
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firebase);
databaseReference = FirebaseDatabase.getInstance().getReference("School");
EDname= (EditText)findViewById(R.id.etname);
addB= (Button)findViewById(R.id.buttonadd);
choose = (Spinner)findViewById(R.id.spinnerchoose);
addB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addData();
}
});
}
private void addData()
{
String name = EDname.getText().toString().trim();
String section = choose.getSelectedItem().toString();
if(!TextUtils.isEmpty(name))
{
String id = databaseReference.push().getKey();
Model model = new Model(id,name,section);
databaseReference.child(id).setValue(model);
Toast.makeText(this,"Artist Added",Toast.LENGTH_LONG).show();
}else
{
Toast.makeText(this,"Enter Name ",Toast.LENGTH_LONG).show();
}
}
}
showFullList.java
public class ShowFullList extends AppCompatActivity {
RecyclerView recyclerViewList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_full_list);
recyclerViewList = (RecyclerView)findViewById(R.id.recyclerview);
}
}
如何使用onStart()
在addEventValueListener
方法中访问firebase实例?
答案 0 :(得分:1)
DatabaseReference
。你可以像这样实现public class ShowFullList extends AppCompatActivity {
RecyclerView recyclerViewList;
DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_full_list);
recyclerViewList = (RecyclerView)findViewById(R.id.recyclerview);
databaseReference = FirebaseDatabase.getInstance().getReference("School");
}
}
。
for ($i = 0, $n = count($array_station) ; $i < $n ; $i++)
{
$station= curl_init();
curl_setopt($station, CURLOPT_VERBOSE, true);
curl_setopt($station, CURLOPT_URL, $array_station[$i]);
curl_setopt($station, CURLOPT_RETURNTRANSFER, true);
curl_setopt($station, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($station);
if (curl_errno($station)){
$response .= 'Retreive Base Page Error: ' . curl_error($station);
}
else {
$skip = intval(curl_getinfo($station, CURLINFO_HEADER_SIZE));
$head = substr($response ,0,$skip);
$response = substr($response ,$skip);
$info = var_export(curl_getinfo($station),true);
}
echo $head;
echo $info;
curl_close($station);
}