我想onItemClick列表视图并转到DetailsPage以显示详细信息,但它为我提供了null。ListView
中的项目是图像URL,名称和地址。
DetailsPage中的项目是图像URL,名称,地址,联系人和类别。
Image of the view on my phone when get null
这是我的ListViewPage
public class ImageListActivity extends AppCompatActivity {
private DatabaseReference mDatabaseRef;
private List<ImageUpload> imgList;
private ListView lv;
private ImageListAdapter adapter;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_list);
imgList = new ArrayList<>();
lv = (ListView) findViewById(R.id.listViewImage);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Please wait loading list image...");
progressDialog.show();
mDatabaseRef = FirebaseDatabase.getInstance().getReference(WorkshopsInfoActivity.FB_DATABASE_PATH);
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressDialog.dismiss();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
ImageUpload img = snapshot.getValue(ImageUpload.class);
imgList.add(img);
}
adapter = new ImageListAdapter(ImageListActivity.this, R.layout.image_item, imgList);
lv.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getApplicationContext(), DetailsOfWorkshops.class);
startActivity(intent);
}
});
}}
这是我的DetailsPage
public class DetailsOfWorkshops extends AppCompatActivity {
DatabaseReference mDatabaseRef;
List<ImageUpload> listImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details_of_workshops);
mDatabaseRef = FirebaseDatabase.getInstance().getReference(WorkshopsInfoActivity.FB_DATABASE_PATH);
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ImageUpload img = dataSnapshot.getValue(ImageUpload.class);
String name = img.getName();
String address = img.getAddress();
String contact = img.getContact();
String category = img.getCategory();
final TextView textViewDetails = (TextView) findViewById(R.id.tvName);
String string = "Name: " + name + "\nAddress: " + address + "\nContact: " + contact + "\nCategory: " + category + "\n\n";
textViewDetails.setText(string);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}}
最佳答案
您不发送任何信息到detail类:
Intent intent = new Intent(getApplicationContext(), DetailsOfWorkshops.class);
startActivity(intent);
尝试使用此:
YourClass item = (YourClass) adapterView.getAdapter().getItem(position);
Intent intent = new Intent(getApplicationContext().this, DetailsOfWorkshops.class);
Bundle bundle = new Bundle();
bundle.putString("valueName", value);
intent.putExtra("MyPackage", bundle);
startActivity(intent);