我有一個(gè)用于 Firebase 聊天的標(biāo)準(zhǔn)聊天顯示方法:private void displayChat() { final ListView listOfMessage = findViewById(R.id.list_of_message); final String DATABASE_URL = "https://firebasestorage.googleapis.com"; Query query = FirebaseDatabase.getInstance().getReference().child("messages").child(chatName).limitToLast(20); FirebaseListOptions<Message> options = new FirebaseListOptions.Builder<Message>() .setLayout(R.layout.list_item) .setQuery(query, Message.class) .setLifecycleOwner(this) .build(); FirebaseListAdapter<Message> adapter = new FirebaseListAdapter<Message>(options) { @Override protected void populateView(View v, Message model, int position) { //Get reference to the views of list_item.xml TextView messageText, messageUser, messageTime; ImageView img; messageText = v.findViewById(R.id.message_text); messageUser = v.findViewById(R.id.message_user); messageTime = v.findViewById(R.id.message_time); img = v.findViewById(R.id.imgView);聊天功能齊全。但是,當(dāng)涉及到圖像時(shí),我必須DATABASE_URL確定接收到的應(yīng)該是圖像而不是文本,因此我將其加載到 Picasso 中,如下所示: if (model.getMessageText().contains(DATABASE_URL)) { messageText.setText("Image sent: "); Picasso.with(getApplicationContext()).load(model.getMessageText()).into(img); }但是,當(dāng)它是普通文本時(shí),我的:else { messageText.setText(model.getMessageText());}將正常顯示文本,但仍顯示圖像 - 始終顯示最近的圖像。我曾嘗試添加img.setVisibility(View.INVISIBLE);到else語句中,以及從 Glide/Picasso 中進(jìn)行等效刪除,但它們最終都會(huì)導(dǎo)致每張圖像都被刪除而不顯示。
Firebase 到 ImageView - 為什么即使沒有圖像,我的聊天也會(huì)顯示圖像?
炎炎設(shè)計(jì)
2021-10-28 15:25:54