From f10cda784bede39a861566850898747c38e6c94f Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期二, 21 一月 2025 15:32:54 +0800 Subject: [PATCH] 2025年01月21日15:31:52 --- countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java b/countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java index 9d4ab2b..78e7381 100644 --- a/countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java +++ b/countrypicker/src/main/java/com/sahooz/library/countrypicker/Adapter.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; + import android.util.TypedValue; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -17,6 +18,7 @@ private final LayoutInflater inflater; private PickCountryCallback callback = null; private final Context context; + public Adapter(Context ctx) { inflater = LayoutInflater.from(ctx); context = ctx; @@ -25,6 +27,7 @@ public void setSelectedCountries(ArrayList<Country> selectedCountries) { this.selectedCountries = selectedCountries; notifyDataSetChanged(); + } public void setCallback(PickCountryCallback callback) { @@ -38,8 +41,9 @@ } private int itemHeight = -1; + public void setItemHeight(float dp) { - itemHeight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, context.getResources().getDisplayMetrics()); + itemHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dp, context.getResources().getDisplayMetrics()); } @SuppressLint("SetTextI18n") @@ -49,13 +53,13 @@ holder.ivFlag.setImageResource(country.flag); holder.tvName.setText(country.translate); holder.tvCode.setText("+" + country.code); - if(itemHeight != -1) { + if (itemHeight != -1) { ViewGroup.LayoutParams params = holder.itemView.getLayoutParams(); params.height = itemHeight; holder.itemView.setLayoutParams(params); } holder.itemView.setOnClickListener(v -> { - if(callback != null) callback.onPick(country); + if (callback != null) callback.onPick(country); }); } -- Gitblit v1.8.0