我想要onItem點擊列表視圖並進入DetailsPage以顯示詳細信息,但它讓我爲空。 ListView
中的項目是圖片網址,名稱和地址。 DetailsPage中的項目是圖片網址,名稱,地址,聯繫人和類別。無法使用onItemClickListener獲取數據
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) {
}
});
}}
對不起,我仍然無法得到它。我的DetailsPage中的代碼有問題嗎? –
問題先生是您不會將任何內容從ImageListActivity發送到DetailsPage活動,以指示要顯示哪個項目。請像上面的Rajesh傢伙一樣做,看看不同。 – julanove