簡體   English   中英

導入 android.content.Context 后無法解析上下文; 吐司

[英]cannot resolve context after importing android.content.Context; The Toast

這是我的代碼塊,我附上了一張圖片。 我不知道為什么“文本”和.show() 看起來是紅色的。

代碼塊:

private void setUpListViewListener() {
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            Context context = getApplicationContext();
            //Context context = getApplicationContext();


            Toast.makeText(context, text: "Item Removed", Toast.LENGTH_LONG).show();

            items.remove((i));
            itemsAdapter.notifyDataSetChanged();
            return true;


        }
    });
}

在此處輸入圖像描述

它的語法錯誤

語法是 -> Toast.makeText(context, text, duration).show();

Toast.makeText(getApplicationContext(), "Item Removed",Toast.LENGTH_LONG).show(); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM