如何从ListView页面获取图像到详细信息视图页面?我只能得到textview并且无法获得imageview。 是我的编码错了吗?我怎么修理它?请帮助我。
这是我的ListView
public static final String IMAGE_NAME= "com.example.weichuan.batupahatcarworkshopsfinder.workshopsId";
private DatabaseReference mDatabaseRef;
private List<ImageUpload> imgList;
private ListView lv;
private ImageListAdapter adapter;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@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();
firebaseAuth = FirebaseAuth.getInstance();
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 position, long l) {
ImageUpload imgList = (ImageUpload) adapterView.getAdapter().getItem(position);
Intent intent = new Intent(ImageListActivity.this, DetailsOfWorkshops.class);
String name = imgList.getName();
String address = imgList.getAddress();
String contact = imgList.getContact();
String category = imgList.getCategory();
String URL = imgList.getUrl();
intent.putExtra("Name", name);
intent.putExtra("Address", address);
intent.putExtra("Contact", contact);
intent.putExtra("Category", category);
intent.putExtra("URL", URL);
startActivity(intent);
}
});
}}
这是我的详细信息视图
DatabaseReference mDatabaseRef;
private TextView textViewAddress;
private TextView textViewContact;
@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) {
Bundle img = getIntent().getExtras();
final String name = img.getString("Name");
final String address = img.getString("Address");
final String contact = img.getString("Contact");
final String category = img.getString("Category");
String URL = img.getString("URL");
final TextView textViewName = (TextView) findViewById(R.id.ImageName);
final TextView textViewAddress = (TextView) findViewById(R.id.ImageAddress);
final TextView textViewContact = (TextView) findViewById(R.id.ImageContact);
final TextView textViewCategory = (TextView) findViewById(R.id.ImageCategory);
final ImageView textViewImage = (ImageView) findViewById(R.id.ImageView);
textViewName.setText(name);
textViewAddress.setText(address);
textViewContact.setText(contact);
textViewCategory.setText(category);
textViewImage.setText(URL);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}}
答案 0 :(得分:0)
您是否正在设置imageview的文字?
textViewImage.setText(URL);
它是possible,但我认为re-download it或get it from internal/external storage会更好。