主頁 > 移動端開發 > 從共享首選項中洗掉專案后如何更新Rcyclerview

從共享首選項中洗掉專案后如何更新Rcyclerview

2022-05-01 05:45:14 移動端開發

我在不同的活動中有一些recyclerview,它們的所有專案都由sharedpreferences指定,但是從sharedpreferences中洗掉一個專案后,recyclerview在我關閉活動并打開它之前不會更新我在洗掉專案后嘗試了notifyDataSetChanged()但似乎它劑量不起作用,這是代碼:

這是我創建共享首選項的 utils 類:

public class Utils {

private static final String ALL_BOOK_KEY = "all_book_key";
private static final String ALREADY_READ_BOOKS = "already_read_books";
private static final String FAVORITE_BOOKS = "favorite_books";
private static final String CURRENTLY_READING_BOOKS = "currently_reading_books";
private static final String WANT_TO_READ_BOOKS = "want_to_read_books";
private static Utils instance;
private final SharedPreferences sharedPreferences;
Gson gson = new Gson();
Type type = new TypeToken<ArrayList<Book>>(){}.getType();


private Utils(Context context) {

    sharedPreferences = context.getSharedPreferences("alternate_db", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();

    if (null == getAllBook()){
        initData();
    }
    if (null == getAlreadyReadBooks()){
        editor.putString(ALREADY_READ_BOOKS, gson.toJson(new ArrayList<Book>()));
        editor.commit();
    }
    if (null == getWantToReadBooks()){
        editor.putString(WANT_TO_READ_BOOKS, gson.toJson(new ArrayList<Book>()));
        editor.commit();
    }
    if (null == getCurrentlyReadingBooks()){
        editor.putString(CURRENTLY_READING_BOOKS, gson.toJson(new ArrayList<Book>()));
        editor.commit();
    }
    if (null == getFavoriteBooks()){
        editor.putString(FAVORITE_BOOKS, gson.toJson(new ArrayList<Book>()));
        editor.commit();
    }

}

private void initData() {

    ArrayList<Book> books = new ArrayList<>();

    books.add(new Book(1, "1Q84", "Haruki Murakami",
            1350,"https://upload.wikimedia.org/wikipedia/pt/thumb/a/a6/1Q84.jpg/230px-1Q84.jpg",
            "A work of maddening brilliance", "The year is 1984 and the city is Tokyo. A young woman named Aomame follows a taxi driver’s enigmatic suggestion and begins to notice puzzling discrepancies in the world around her. She has entered, she realizes, a parallel existence, which she calls 1Q84 “Q is for ‘question mark.’ A world that bears a question.” Meanwhile, an aspiring writer named Tengo takes on a suspect ghostwriting project. He becomes so wrapped up with the work and its unusual author that, soon, his previously placid life begins to come unraveled. As Aomame’s and Tengo’s narratives converge over the course of this single year, we learn of the profound and tangled connections that bind them ever closer: a beautiful, dyslexic teenage girl with a unique vision; a mysterious religious cult that instigated a shoot-out with the metropolitan police; a reclusive, wealthy dowager who runs a shelter for abused women; a hideously ugly private investigator; a mild-mannered yet ruthlessly efficient bodyguard; and a peculiarly insistent television-fee collector. A love story, a mystery, a fantasy, a novel of self-discovery, a dystopia to rival George Orwell’s 1Q84 is Haruki Murakami’s most ambitious undertaking yet: an instant best seller in his native Japan, and a tremendous feat of imagination from one of our most revered contemporary writers."));

    books.add(new Book(2,  "1984", "George Orwell", 328, "https://www.jiomart.com/images/product/600x600/rvkysatqkb/1984-hindi-george-orwell-paperback-296-pages-product-images-orvkysatqkb-p590846049-0-202111091023.jpg","follows the life of Winston Smith, a low ranking member of 'the Party', who is frustrated by the omnipresent eyes of the party, and its ominous ruler Big Brother", "1984 by George Orwell – review ‘Orwell’s novella is a warning for the human race’  Conheeneyl Sun 29 May 2016 12.00 BST War is Peace. Freedom is Slavery. Ignorance is Strength.  1984 is a dystopian novella by George Orwell published in 1949, which follows the life of Winston Smith, a low ranking member of ‘the Party’, who is frustrated by the omnipresent eyes of the party, and its ominous ruler Big Brother.  ‘Big Brother’ controls every aspect of people’s lives. It has invented the language ‘Newspeak’ in an attempt to completely eliminate political rebellion; created ‘Throughtcrimes’ to stop people even thinking of things considered rebellious. The party controls what people read, speak, say and do with the threat that if they disobey, they will be sent to the dreaded Room 101 as a looming punishment.  Orwell effectively explores the themes of mass media control, government surveillance, totalitarianism and how a dictator can manipulate and control history, thoughts, and lives in such a way that no one can escape it.  1984 The protagonist, Winston Smith, begins a subtle rebellion against the party by keeping a diary of his secret thoughts, which is a deadly thoughtcrime. With his lover Julia, he begins a foreordained fight for freedom and justice, in a world where no one else appears to see, or dislike, the oppression the protagonist opposes.  Perhaps the most powerful, effective and frightening notion of 1984 is that the complete control of an entire nation under a totalitarian state is perfectly possible. If the world fell under the control of one or even multiple dictators, the future could easily become a twisted, cruel world where every movement, word and breath is scrutinised by an omnipotent, omnipresent power that no one can stop, or even oppose without the fear of death.  How do I get involved in the Guardian children\'s books site? Read more Orwell’s novella is a warning for the human race. It highlights the importance of resisting mass control and oppression."));

    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(ALL_BOOK_KEY, gson.toJson(books));
    editor.commit();
}


public static Utils getInstance(Context context) {
    if (null == instance) {
        instance = new Utils(context);
    }
    return instance;
}

public ArrayList<Book> getAllBook() {
    return gson.fromJson(sharedPreferences.getString(ALL_BOOK_KEY, null), type);
}

public ArrayList<Book> getAlreadyReadBooks() {
    return gson.fromJson(sharedPreferences.getString(ALREADY_READ_BOOKS, null),type);
}

public ArrayList<Book> getWantToReadBooks() {
    return gson.fromJson(sharedPreferences.getString(WANT_TO_READ_BOOKS, null), type);
}

public ArrayList<Book> getCurrentlyReadingBooks() {
    return gson.fromJson(sharedPreferences.getString(CURRENTLY_READING_BOOKS,null), type);
}

public ArrayList<Book> getFavoriteBooks() {
    return gson.fromJson(sharedPreferences.getString(FAVORITE_BOOKS, null), type);
}

public Book getBookById(int id) {
    ArrayList<Book> books = getAllBook();

    if(null != books){
        for (Book b : books) {
            if (b.getId() == id) {
                return b;
            }
        }
    }

    return null;
}

public boolean addToAlreadyReadBook(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getAlreadyReadBooks();
    if(null != books){
        if (books.add(book)){
            return addToSharedPreferences(books, ALREADY_READ_BOOKS);
        }
    }
    return false;
}

public boolean addToWantToReadBook(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getWantToReadBooks();
    if(null != books){
        if(books.add(book)){
            return addToSharedPreferences(books, WANT_TO_READ_BOOKS);
        }
    }
    return false;
}

public boolean addToCurrentlyReading(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getCurrentlyReadingBooks();
    if(null != books){
        if(books.add(book)){
            return addToSharedPreferences(books, CURRENTLY_READING_BOOKS);
        }
    }
    return false;
}

public boolean addToFavorite(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getFavoriteBooks();
    if(null != books){
        if(books.add(book)){
            return addToSharedPreferences(books, FAVORITE_BOOKS);
        }

    }

    return false;
}

public boolean removeFromWantToRead(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getWantToReadBooks();
    if(null != books){
        for (Book b: books){
            if(b.getId() == book.getId()){
                if (books.remove(b)){
                    return addToSharedPreferences(books, WANT_TO_READ_BOOKS);
                }
            }
        }

    }
    return false;
}

public boolean removeFromAlreadyReadBook(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getAlreadyReadBooks();
    if(null != books){
        for (Book b: books){
            if(b.getId() == book.getId()){
                if (books.remove(b)){
                    return addToSharedPreferences(books, ALREADY_READ_BOOKS);
                }
            }
        }

    }
    return false;
}

public boolean removeFromFavoriteBook(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getFavoriteBooks();
    if(null != books){
        for (Book b: books){
            if(b.getId() == book.getId()){
                if (books.remove(b)){
                    return addToSharedPreferences(books, FAVORITE_BOOKS);
                }
            }
        }

    }
    return false;
}

public boolean removeFromCurrentlyReadingBook(Book book){
    book.setExpanded(false);
    ArrayList<Book> books = getCurrentlyReadingBooks();
    if(null != books){
        for (Book b: books){
            if(b.getId() == book.getId()){
                if (books.remove(b)){
                    return addToSharedPreferences(books, CURRENTLY_READING_BOOKS);
                }
            }
        }

    }
    return false;
}

public boolean addToSharedPreferences(ArrayList<Book> books, String name){
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.remove(name);
    editor.putString(name, gson.toJson(books));
    editor.commit();
    return true;
}

}

這是我的 recyclerview 采用者類,每當用戶單擊警報對話框中的“是”按鈕時,我正在呼叫負責從 utils 類中的 sharedpreferences 中洗掉專案的方法:

public class BookRecAdopter extends RecyclerView.Adapter<BookRecAdopter.ViewHolder>{

private static final String TAG = "BookRecAdopter";
private ArrayList<Book> books = new ArrayList<>();
private final Context mContext;
private final String parentActivity;

public BookRecAdopter(Context mContext, String parentActivity) {
    this.mContext = mContext;
    this.parentActivity = parentActivity;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_book, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
    Log.d(TAG, "onBindViewHolder: Called");
    holder.txtName.setText(books.get(position).getName());
    Glide.with(mContext).asBitmap().load(books.get(position).getImageUrl()).into(holder.imgBook);

    holder.parent.setOnClickListener(view -> {
        Intent intent = new Intent(mContext, BookActivity.class);
        intent.putExtra(BOOK_ID_KEY, books.get(position).getId());
        mContext.startActivity(intent);
    });


    holder.txtAuthor.setText(books.get(position).getAuthor());
    holder.txtDescription.setText(books.get(position).getShortDesc());
    holder.bookNameFull.setText(books.get(position).getName());

    if (books.get(position).isExpanded()){
        TransitionManager.beginDelayedTransition(holder.parent);
        holder.expandedRelLayout.setVisibility(View.VISIBLE);
        holder.downArrow.setVisibility(View.GONE);
        holder.txtName.setVisibility(View.GONE);
        switch (parentActivity) {
            case "allBook":
                holder.btnDelete.setVisibility(View.GONE);
                break;
            case "wantToReadBook":
                holder.btnDelete.setVisibility(View.VISIBLE);
                holder.btnDelete.setOnClickListener(view -> {
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                    builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                        if (Utils.getInstance(mContext).removeFromWantToRead(books.get(position))) {
                            Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                            notifyDataSetChanged();
                        }
                    });
                    builder.setNegativeButton("No", (dialogInterface, i) -> {

                    });
                    builder.create().show();

                });
                break;
            case "alreadyReadBook":
                holder.btnDelete.setVisibility(View.VISIBLE);
                holder.btnDelete.setOnClickListener(view -> {
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                    builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                        if(Utils.getInstance(mContext).removeFromAlreadyReadBook(books.get(position))){
                            Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                            notifyDataSetChanged();

                        }
                    });
                    builder.setNegativeButton("No", (dialogInterface, i) -> {

                    });
                    builder.create().show();

                });
                break;
            case "favoriteBook":
                holder.btnDelete.setVisibility(View.VISIBLE);
                holder.btnDelete.setOnClickListener(view -> {
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setMessage("are you sure you want to delete "   books.get(position).getName()   "?");
                    builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                        if(Utils.getInstance(mContext).removeFromFavoriteBook(books.get(position))){
                            Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                            notifyDataSetChanged();

                        }
                    });
                    builder.setNegativeButton("No", (dialogInterface, i) -> {

                    });
                    builder.create().show();

                });
                break;
            case "currentlyReadBook":
                holder.btnDelete.setVisibility(View.VISIBLE);
                holder.btnDelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                if(Utils.getInstance(mContext).removeFromCurrentlyReadingBook(books.get(position))){
                                    Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                                    notifyDataSetChanged();

                                }
                            }
                        });
                        builder.setNegativeButton("No", (dialogInterface, i) -> {

                        });
                        builder.create().show();

                    }
                });
                break;
        }
    }
    else{
        TransitionManager.beginDelayedTransition(holder.parent);
        holder.expandedRelLayout.setVisibility(View.GONE);
        holder.downArrow.setVisibility(View.VISIBLE);
        holder.txtName.setVisibility(View.VISIBLE);
    }
    
}


@Override
public int getItemCount() {
    return books.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
    private final CardView parent;
    private final ImageView imgBook;
    private final ImageView downArrow;
    private final TextView txtName, txtAuthor, txtDescription, bookNameFull, btnDelete;
    private final RelativeLayout expandedRelLayout;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        parent = itemView.findViewById(R.id.parent);
        imgBook = itemView.findViewById(R.id.imgBook);
        txtName = itemView.findViewById(R.id.txtBookName);
        downArrow = itemView.findViewById(R.id.btnDownArrow);
        ImageView upArrow = itemView.findViewById(R.id.btnUpArrow);
        expandedRelLayout = itemView.findViewById(R.id.expandedRelLayout);
        txtAuthor = itemView.findViewById(R.id.txtAuthor);
        txtDescription = itemView.findViewById(R.id.txtShortDec);
        bookNameFull = itemView.findViewById(R.id.bookNameFull);
        btnDelete = itemView.findViewById(R.id.btnDelete);

        downArrow.setOnClickListener(view -> {
            Book book = books.get(getAdapterPosition());
            book.setExpanded(!book.isExpanded());
            notifyItemChanged(getAdapterPosition());
        });

        upArrow.setOnClickListener(view -> {
            Book book = books.get(getAdapterPosition());
            book.setExpanded((!book.isExpanded()));
            notifyItemChanged(getAdapterPosition());
        });

    }
}

public void setBooks(ArrayList<Book> books) {
    this.books = books;
    notifyDataSetChanged();
}

}

這是recyclerview存在的活動之一,它從sharedprefereces中獲取專案:

public class Favorite extends AppCompatActivity {
RecyclerView favoriteRec;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_favorite);

    favoriteRec = findViewById(R.id.favoriteRec);
    BookRecAdopter books = new BookRecAdopter(this, "favoriteBook");
    books.setBooks(Utils.getInstance(this).getFavoriteBooks());
    favoriteRec.setAdapter(books);
    favoriteRec.setLayoutManager(new LinearLayoutManager(this));
}

@Override
public void onBackPressed(){
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    overridePendingTransition(R.anim.close_in, R.anim.close_out);
}

}

我想我必須在 sharedpreferences 發生任何變化后重寫一些回呼方法來更新 recyclerview 但我不知道是哪一個以及在哪里

我很感激任何幫助。

uj5u.com熱心網友回復:

首先,在配置您的RecyclerView設定時,它的布局管理器在其配接器之前:

BookRecAdopter books = new BookRecAdopter(this, "favoriteBook");
favoriteRec.setLayoutManager(new LinearLayoutManager(this));
favoriteRec.setAdapter(books);

然后,鑒于您的專案結構,我認為您應該直接從Utils類中填充配接器的資料。
嘗試在配接器內部定義一個更新書籍串列(updateBooks)的內部方法,并在每次洗掉后和初始化時呼叫它。

public class BookRecAdopter extends RecyclerView.Adapter<BookRecAdopter.ViewHolder>{

    private static final String TAG = "BookRecAdopter";
    private ArrayList<Book> books = new ArrayList<>();
    private final Context mContext;
    private final String parentActivity;

    public BookRecAdopter(Context mContext, String parentActivity) {
        this.mContext = mContext;
        this.parentActivity = parentActivity;
        updateBooks();
    }

    private void updateBooks() {
        switch (parentActivity) {
            case "allBook":
                this.books = Utils.getInstance(mContext).getAllBooks();
                break;
            case "wantToReadBook":
                this.books = Utils.getInstance(mContext).getWantToReadBooks();
                break;
            case "alreadyReadBook":
                this.books = Utils.getInstance(mContext).getAlreadyReadBooks();
                break;
            case "favoriteBook":
                this.books = Utils.getInstance(mContext).getFavoriteBooks();
                break;
            case "currentlyReadBook":
                this.books = Utils.getInstance(mContext).getCurrentlyReadingBooks();
                break;
            default:
                break;
        }
        this.notifyDataSetChanged();
    }

    ...

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        ...

        if (books.get(position).isExpanded()){
            ...
            switch (parentActivity) {
                case "wantToReadBook":
                    holder.btnDelete.setVisibility(View.VISIBLE);
                    holder.btnDelete.setOnClickListener(view -> {
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                        builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                            if (Utils.getInstance(mContext).removeFromWantToRead(books.get(position))) {
                                Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                                updateBooks();
                            }
                        });
                        builder.setNegativeButton("No", (dialogInterface, i) -> {

                        });
                        builder.create().show();

                    });
                    break;
                case "alreadyReadBook":
                    holder.btnDelete.setVisibility(View.VISIBLE);
                    holder.btnDelete.setOnClickListener(view -> {
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                        builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                            if(Utils.getInstance(mContext).removeFromAlreadyReadBook(books.get(position))){
                                Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                                updateBooks();
                            }
                        });
                        builder.setNegativeButton("No", (dialogInterface, i) -> {

                        });
                        builder.create().show();

                    });
                    break;
                case "favoriteBook":
                    holder.btnDelete.setVisibility(View.VISIBLE);
                    holder.btnDelete.setOnClickListener(view -> {
                        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                        builder.setMessage("are you sure you want to delete "   books.get(position).getName()   "?");
                        builder.setPositiveButton("Yes", (dialogInterface, i) -> {
                            if(Utils.getInstance(mContext).removeFromFavoriteBook(books.get(position))){
                                Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                                updateBooks();
                            }
                        });
                        builder.setNegativeButton("No", (dialogInterface, i) -> {

                        });
                        builder.create().show();

                    });
                    break;
                case "currentlyReadBook":
                    holder.btnDelete.setVisibility(View.VISIBLE);
                    holder.btnDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                            builder.setMessage("Are you sure you want to delete "   books.get(position).getName()   "?");
                            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    if(Utils.getInstance(mContext).removeFromCurrentlyReadingBook(books.get(position))){
                                        Toast.makeText(mContext, "Book Removed", Toast.LENGTH_SHORT).show();
                                        updateBooks();
                                    }
                                }
                            });
                            builder.setNegativeButton("No", (dialogInterface, i) -> {

                            });
                            builder.create().show();

                        }
                    });
                    break;
            }
        }
        ...
    }

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/468692.html

標籤:爪哇 安卓 安卓工作室 android-recyclerview 共享偏好

上一篇:完全錯誤:在org.gradle.api.internal.artifacts.dsl.dependencies.Def型別的物件上找不到引數[directory'libs']的方

下一篇:當我能夠模擬android4.1及更高版本時,為什么我無法模擬android2.3.3?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more