当在recordCust活动(如下)中单击listview时,数据应显示在Parcel_DM活动(以上)中。问题是我不知道如何检索火力数据回来时,单击列表视图。当我单击列表视图时,数据不会显示。
您的帮助将非常感激,非常感谢你。
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
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;
public class Parcel_DM extends AppCompatActivity {
// Button Track;
TextView textView1;
ListView listViewDM;
DatabaseReference table_dm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.parcel_dm);
// Track = (Button) findViewById(R.id.btn_track);
textView1 = (TextView) findViewById(R.id.parcelView);
listViewDM = (ListView) findViewById(R.id.listViewDeliveryMan);
table_dm = FirebaseDatabase.getInstance().getReference("DeliveryMan");
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String postSnapshot = parent.getItemAtPosition(position).toString();
table_dm.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
if(postSnapshot.getKey() != null) {
//DeliveryMan stall = postSnapshot.getValue(DeliveryMan.class);
// String key = stall.getPhone();
textView1 = (TextView) findViewById(R.id.parcelView);
textView1.append("Name:" + postSnapshot.child("name").getValue().toString() + "\n");
textView1.append("Phone:" + postSnapshot.child("phone").getValue().toString() + "\n");
textView1.append("Address:" + postSnapshot.child("adress").getValue().toString() + "\n");
textView1.append("Postcode:" + postSnapshot.child("postcode").getValue().toString() + "\n");
Intent homeIntent = getIntent();
if (homeIntent.hasExtra("DeliveryMan")) {
textView1.setText(homeIntent.getStringExtra("DeliveryMan"));
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
**
**
listViewDM.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
table_dm.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
if(postSnapshot.getKey() != null) {
textView1 = (TextView) findViewById(R.id.parcelView);
DeliveryMan stall = postSnapshot.getValue(DeliveryMan.class);
DeliveryMan deliveryMan = deliveryman.get(position);
String key = deliveryMan.getPhone();
deliveryman.add(stall);
Intent homeIntent = new Intent(RecordCust.this, Parcel_DM.class);
homeIntent.putExtra("position", position);
startActivity(homeIntent);
finish();
}
}
listViewDM.setAdapter(artistAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}