ListView 自定义item布局 android.widget.LinearLayout$LayoutParams

本文记录了一个关于Android应用开发中布局参数设置不当导致的ClassCastException错误。具体表现为试图将LinearLayout.LayoutParams类型参数赋给不适合的父布局,解决方法是确保子视图的LayoutParams与父布局相匹配。

05-09 10:51:21.522: ERROR/AndroidRuntime(4425): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams


setListAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout lnLayout = new LinearLayout(ListActivityDemo02.this); // lnLayout.setLayoutParams(new LinearLayout.LayoutParams( // ViewGroup.LayoutParams.FILL_PARENT, android.R.attr.listPreferredItemHeight)); lnLayout.setOrientation(LinearLayout.VERTICAL); ViewGroup.LayoutParams tvLayout = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); TextView tv = new TextView(ListActivityDemo02.this); tv.setText("hello world"); tv.setLayoutParams(tvLayout); lnLayout.addView(tv); TextView tv2 = new TextView(ListActivityDemo02.this); tv2.setText("hello world111111111"); tv2.setLayoutParams(tvLayout); lnLayout.addView(tv2); return lnLayout; } @Override public long getItemId(int position) { return 1; } @Override public Object getItem(int position) { return null; } @Override public int getCount() { return 1; } });


如果对外层的 Layout设置属性的话,

lnLayout.setLayoutParams(new LinearLayout.LayoutParams(

ViewGroup.LayoutParams.FILL_PARENT, android.R.attr.listPreferredItemHeight));


则会报错。。。如上的错误信息,,具体的如下

解决办法就是取消对其中的设置


05-05 18:42:22.331: ERROR/AndroidRuntime(5833): ERROR: thread attach failed 05-05 18:42:23.581: ERROR/AndroidRuntime(5848): Uncaught handler: thread main exiting due to uncaught exception 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.ListView.setupChild(ListView.java:1702) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.ListView.makeAndAddView(ListView.java:1671) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.ListView.fillDown(ListView.java:637) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.ListView.fillFromTop(ListView.java:694) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.ListView.layoutChildren(ListView.java:1521) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.AbsListView.onLayout(AbsListView.java:1113) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:900) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.View.layout(View.java:6834) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.ViewRoot.performTraversals(ViewRoot.java:1016) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.view.ViewRoot.handleMessage(ViewRoot.java:1666) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.os.Handler.dispatchMessage(Handler.java:99) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.os.Looper.loop(Looper.java:123) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at android.app.ActivityThread.main(ActivityThread.java:4603) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at java.lang.reflect.Method.invokeNative(Native Method) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at java.lang.reflect.Method.invoke(Method.java:521) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 05-05 18:42:23.601: ERROR/AndroidRuntime(5848): at dalvik.system.NativeStart.main(Native Method) 05-05 18:42:25.341: ERROR/PackageInstallationReceiver(146): Remove /data/local/tmp/com.mmb.shop.apk Fail! 05-05 18:42:34.381: ERROR/ActivityManager(88): fail to set top app changed!



看到http://hi.baidu.com/ljlkings/blog/item/86ed2401029b4efd08fa9303.html


受到了一点启发 :


Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
2010-12-21 17:38

These supply parameters to theparentof this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children.

So basically, if you are adding a view to another, you MUST set the LayoutParams of the view to the LayoutParams type that the parent uses, or you will get a runtime error.

就是說你要設置此layoutparameters須對父對象佈局設定,最上層的layout不需設定此項。

编写一个Android应用,其中包含一个列表框(ListView)。列表框应显示一系列项目,例如“项目1”、“项目2”和“项目3”。当列表中的项目被点击时,应显示一个Toast消息,显示被点击项目的文本。 MainActivity.java import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private ListView listView; private String[] items = {"项目1", "项目2", "项目3"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = findViewById(R.id.my_listview); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String item = items[position]; Toast.makeText(MainActivity.this, "你点击了:" + item, Toast.LENGTH_SHORT).show(); } }); } } activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ListView android:id="@+id/my_listview" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> 修改建议: 1添加更多列表项到items数组中。 2更改列表项的布局(例如使用自定义的列表项布局)。 3尝试在点击事件中执行其他操作,如导航到另一个Activity或更新UI。 4调整ListView的高度,比如设置为wrap_content或指定具体的dp值。(给出详细步骤)
06-06
package com.weishitechsub.kdcxqwb.dialog; import android.app.Dialog; import android.content.Context; import android.graphics.Rect; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.weishitechsub.kdcxqwb.R; import com.weishitechsub.kdcxqwb.bean.ListBean; import com.weishitechsub.kdcxqwb.fragment.Adapter.CourierAdapter; import java.util.List; public class BottomSheetDialogUtil { public interface OnCourierSelectedListener { void onCourierSelected(String selectedCourier, String num); } public static void showBottomSelectionDialog(Context context, List<ListBean> courierList, OnCourierSelectedListener listener) { BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context, R.style.BottomSheetStyle); View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_selection, null); EditText etSearch = view.findViewById(R.id.et_search); RecyclerView recyclerView = view.findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(context)); // 创建适配器 CourierAdapter courierAdapter = new CourierAdapter(courierList, (courier, num) -> { bottomSheetDialog.dismiss(); if (listener != null) { listener.onCourierSelected(courier, num); } }); recyclerView.setAdapter(courierAdapter); // 🔍 添加搜索功能 etSearch.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { courierAdapter.filter(s.toString()); } @Override public void afterTextChanged(Editable s) {} }); // 设置 BottomSheet 行为 View bottomSheetInternal = view.findViewById(R.id.design_bottom_sheet); // 如果你的 layout 根布局有这个 id if (bottomSheetInternal == null) { // 否则用 content view bottomSheetInternal = view; } BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(bottomSheetInternal); behavior.setDraggable(true); behavior.setHalfExpandedRatio(0.6f); behavior.setState(BottomSheetBehavior.STATE_EXPANDED); // ✅ 关键:让整个 BottomSheet 可以随键盘上推 // 注意:必须在 setCancelable 之前调用,否则无效 bottomSheetDialog.setContentView(view, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT )); // 获取 Window 并设置 softInputMode Window window = bottomSheetDialog.getWindow(); if (window != null) { window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); window.setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } // ✅ 可选:打开键盘 etSearch.post(() -> { etSearch.requestFocus(); InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(etSearch, InputMethodManager.SHOW_IMPLICIT); }); bottomSheetDialog.show(); } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="400dp" android:orientation="vertical" android:id="@+id/design_bottom_sheet" android:background="@android:color/white"> <!-- 标题栏 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="?attr/colorPrimary"> <TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择运输商" android:textSize="18sp" android:textStyle="bold" android:gravity="center" android:padding="16dp" android:textColor="@android:color/white" /> </LinearLayout> <!-- 分隔线 --> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <!-- 搜索框 --> <EditText android:id="@+id/et_search" android:layout_width="match_parent" android:layout_height="48dp" android:layout_margin="12dp" android:padding="12dp" android:hint="搜索快递公司..." android:textSize="14sp" android:background="@drawable/shuru_bg" android:drawableStart="@drawable/ic_search_sized" android:drawablePadding="8dp" /> <!-- 使用RecyclerView替代ListView,避免滑动冲突 --> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:scrollbars="vertical" /> </LinearLayout>报错 java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout
最新发布
11-29
package com.XiaoLian; import adrt.ADRTLogCatReader; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Process; import android.provider.Settings; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import com.XiaoLian.IPCCond.AIDLConnection; import com.XiaoLian.IPCCond.IPCService; import com.XiaoLian.ToolClass.FloatTool; import com.XiaoLian.ToolClass.SPUtils; import com.XiaoLian.ToolClass.fileUtil; import com.topjohnwu.superuser.ipc.RootService; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public class MainActivity extends Activity { private static MyAdapter adapter; static AlertDialog alertDialogs; static AlertDialog alertDialogs1; private static AlertDialog alertDialogss; public static Context context; private static AlertDialog dialog; static AlertDialog.Builder dialogs; static AlertDialog.Builder dialogs1; public static Context getContext; static LinearLayout linearLayouts; private static List<Map<String, Object>> list; private static ListView listView; private static Activity m_activity; private static TextView prog_text; private static ProgressBar progressBar; /* renamed from: 倒计时 reason: contains not printable characters */ private static TextView f0; /* renamed from: 窗口 reason: contains not printable characters */ private static View f3; /* renamed from: 读 reason: contains not printable characters */ private static EditText f4; private AlertDialog dialogsShow; private Handler handler = new Handler(this) { // from class: com.XiaoLian.MainActivity.100000009 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000009 r4) { return r4.this$0; } @Override // android.os.Handler public void handleMessage(Message message) { super.handleMessage(message); MainActivity.time--; MainActivity.f0.setText(new StringBuffer().append(new StringBuffer().append("倒计时 ").append(MainActivity.time).toString()).append(" 秒").toString()); if (MainActivity.time == 0) { MainActivity.dialog.dismiss(); this.this$0.handler.removeMessages(0); } this.this$0.handler.sendEmptyMessageDelayed(0, (long) 1000); } }; public Intent intent; /* renamed from: 卡密 reason: contains not printable characters */ private String f5; /* renamed from: 卡密内容 reason: contains not printable characters */ private String f6; static String wy_url = "https://wy.llua.cn"; static String WY_APPID = "61456"; static String WY_APPKEY = "tJY6OZR4KQ2PlwM9RWKPRh"; static String WY_RC4KEY = "lwM9RWKPRhGtJY6OZR4KQ2P"; /* renamed from: 当前版本号 reason: contains not printable characters */ static String f1 = "1.0"; /* renamed from: 登录判断 reason: contains not printable characters */ static boolean f2 = false; private static boolean init_win = false; private static int time = 1; public static boolean app_init_mode = false; public static boolean app_Operation_mode_root = false; @Override // android.app.Activity protected void onCreate(Bundle bundle) { ADRTLogCatReader.onContext(this, "com.aide.ui"); super.onCreate(bundle); requestWindowFeature(1); if (Build.VERSION.SDK_INT >= 23) { getWindow().getDecorView().setSystemUiVisibility(8192); } getWindow().setStatusBarColor(Color.parseColor("#E1F0F0F0")); requestPermission(); m1(); m_activity = this; getContext = this; SelectModeBox(this); } /* renamed from: 读取文件 reason: contains not printable characters */ public static String m0(String str) { String str2 = ""; try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(str)), "UTF-8")); String str3 = null; while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } str2 = new StringBuffer().append(str2).append(readLine).toString(); } } catch (Exception e) { e.printStackTrace(); } return str2; } /* renamed from: 储存权限 reason: contains not printable characters */ public void m1() { boolean z = true; if (Build.VERSION.SDK_INT >= 23) { if (checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") != 0) { z = false; } if (checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != 0) { z = false; } if (!z) { requestPermissions(new String[]{"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}, 102); } } } private void initMain() { f3.findViewById(R.id.go_app).setVisibility(8); loadDeploy(new Object[][]{new Object[]{"ROOT权限", new Runnable(this) { // from class: com.XiaoLian.MainActivity.100000002 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000002 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { if (MainActivity.app_Operation_mode_root && !Util.isRoot()) { new Handler(Looper.getMainLooper()).post(new Runnable(this) { // from class: com.XiaoLian.MainActivity.100000002.100000001 private final AnonymousClass100000002 this$0; { this.this$0 = r6; } static AnonymousClass100000002 access$0(AnonymousClass100000001 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(AnonymousClass100000002.access$0(this.this$0)); builder.setTitle("提示"); builder.setMessage("无法获取ROOT权限,请检查您的设备是否已ROOT?"); builder.setCancelable(false); builder.setPositiveButton("确定", new DialogInterface.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000002.100000001.100000000 private final AnonymousClass100000001 this$0; { this.this$0 = r6; } static AnonymousClass100000001 access$0(AnonymousClass100000000 r4) { return r4.this$0; } @Override // android.content.DialogInterface.OnClickListener public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); Process.killProcess(Process.myPid()); System.exit(0); } }); AlertDialog create = builder.create(); create.getWindow().setType(2038); create.show(); } }); try { Thread.sleep((long) 999999999); } catch (InterruptedException e) { e.printStackTrace(); } } } }}, new Object[]{"悬浮窗权限", new Runnable(this) { // from class: com.XiaoLian.MainActivity.100000003 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000003 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { for (int i = 0; i < 5 && !Settings.canDrawOverlays(this.this$0); i++) { Util.runShell(new StringBuffer().append(new StringBuffer().append("appops set --uid ").append(this.this$0.getPackageName()).toString()).append(" android:system_alert_window allow").toString(), true); try { Thread.sleep((long) 250); } catch (InterruptedException e) { e.printStackTrace(); } } if (!Settings.canDrawOverlays(this.this$0)) { this.this$0.startActivityForResult(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse(new StringBuffer().append("package:").append(this.this$0.getPackageName()).toString())), 4444); } while (!Settings.canDrawOverlays(this.this$0)) { try { Thread.sleep((long) 750); } catch (InterruptedException e2) { e2.printStackTrace(); } } } }}, new Object[]{"连接服务", new Runnable(this) { // from class: com.XiaoLian.MainActivity.100000005 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000005 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { while (!IPCService.isConnect() && MainActivity.app_Operation_mode_root) { try { Thread.sleep((long) 1000); } catch (InterruptedException e) { e.printStackTrace(); } } this.this$0.runOnUiThread(new Runnable(this) { // from class: com.XiaoLian.MainActivity.100000005.100000004 private final AnonymousClass100000005 this$0; { this.this$0 = r6; } static AnonymousClass100000005 access$0(AnonymousClass100000004 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { AnonymousClass100000005.access$0(this.this$0).handler.sendEmptyMessageDelayed(0, (long) 1000); MainActivity.f3.findViewById(R.id.go_app).setVisibility(0); } }); } }}}); } private void loadDeploy(Object[][] objArr) { new Thread(new Runnable(this, objArr) { // from class: com.XiaoLian.MainActivity.100000008 private final MainActivity this$0; private final Object[][] val$funs; { this.this$0 = r7; this.val$funs = r8; } static MainActivity access$0(AnonymousClass100000008 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { MainActivity.progressBar.setMax(this.val$funs.length); for (int i = 0; i < this.val$funs.length; i++) { HashMap hashMap = new HashMap(); this.this$0.runOnUiThread(new Runnable(this, i, this.val$funs, hashMap) { // from class: com.XiaoLian.MainActivity.100000008.100000006 private final AnonymousClass100000008 this$0; private final int val$finalI; private final Object[][] val$funs; private final HashMap val$map; { this.this$0 = r9; this.val$finalI = r10; this.val$funs = r11; this.val$map = r12; } static AnonymousClass100000008 access$0(AnonymousClass100000006 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { MainActivity.prog_text.setText(String.format("(%d/%d)", new Integer(this.val$finalI + 1), new Integer(this.val$funs.length))); this.val$map.put("msg", this.val$funs[this.val$finalI][0].toString()); this.val$map.put("success", new Boolean(false)); MainActivity.list.add(this.val$map); MainActivity.adapter.notifyDataSetChanged(); } }); ((Runnable) this.val$funs[i][1]).run(); this.this$0.runOnUiThread(new Runnable(this, hashMap, i) { // from class: com.XiaoLian.MainActivity.100000008.100000007 private final AnonymousClass100000008 this$0; private final int val$finalI; private final HashMap val$map; { this.this$0 = r8; this.val$map = r9; this.val$finalI = r10; } static AnonymousClass100000008 access$0(AnonymousClass100000007 r4) { return r4.this$0; } @Override // java.lang.Runnable public void run() { this.val$map.replace("success", new Boolean(true)); MainActivity.adapter.notifyDataSetChanged(); MainActivity.listView.setSelection(MainActivity.listView.getBottom()); MainActivity.progressBar.setProgress(this.val$finalI + 1); } }); } } }).start(); } /* access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class MyAdapter extends BaseAdapter { private List<Map<String, Object>> list; private LayoutInflater mInflater; private final MainActivity this$0; static MainActivity access$0(MyAdapter myAdapter) { return myAdapter.this$0; } public MyAdapter(MainActivity mainActivity, Context context, List<Map<String, Object>> list) { this.this$0 = mainActivity; this.mInflater = LayoutInflater.from(context); this.list = list; } @Override // android.widget.Adapter public int getCount() { return this.list.size(); } @Override // android.widget.Adapter public Object getItem(int i) { return this.list.get(i); } @Override // android.widget.Adapter public long getItemId(int i) { return (long) i; } @Override // android.widget.Adapter public View getView(int i, View view, ViewGroup viewGroup) { ViewHolder viewHolder; View view2 = view; if (view2 == null) { viewHolder = new ViewHolder(this); view2 = this.mInflater.inflate(R.layout.layout_main_item, (ViewGroup) null); viewHolder.msg = (TextView) view2.findViewById(R.id.main_item_msg); viewHolder.success = (ImageView) view2.findViewById(R.id.main_item_success); viewHolder.progressBar = (ProgressBar) view2.findViewById(R.id.progressBar2); view2.setTag(viewHolder); } else { viewHolder = (ViewHolder) view2.getTag(); } viewHolder.msg.setText((String) this.list.get(i).get("msg")); boolean booleanValue = ((Boolean) this.list.get(i).get("success")).booleanValue(); viewHolder.success.setVisibility(booleanValue ? 0 : 8); viewHolder.progressBar.setVisibility(booleanValue ? 8 : 0); return view2; } /* loaded from: classes.dex */ public final class ViewHolder { public TextView msg; public ProgressBar progressBar; public ImageView success; private final MyAdapter this$0; static MyAdapter access$0(ViewHolder viewHolder) { return viewHolder.this$0; } public ViewHolder(MyAdapter myAdapter) { this.this$0 = myAdapter; } } } /* access modifiers changed from: private */ public void ActivityMain() { if (app_Operation_mode_root) { try { RootService.bind(new Intent(this, Class.forName("com.XiaoLian.IPCCond.SuperMain")), new AIDLConnection(false)); if (!Settings.canDrawOverlays(m_activity)) { FloatTool.RunShell(new StringBuffer().append(new StringBuffer().append("appops set --uid ").append(m_activity.getPackageName()).toString()).append(" android:system_alert_window allow").toString(), true); } } catch (ClassNotFoundException e) { throw new NoClassDefFoundError(e.getMessage()); } } else { System.loadLibrary("main"); RequestPermission(); } app_init_mode = true; SPUtils.setParam(getApplicationContext(), "app_init_mode", new Boolean(app_init_mode)); SPUtils.setParam(getApplicationContext(), "app_Operation_mode_root", new Boolean(app_Operation_mode_root)); setContentView(R.layout.main_mocn); f3 = LayoutInflater.from(this).inflate(R.layout.activity_main, (ViewGroup) null); listView = (ListView) f3.findViewById(R.id.list_start_info); progressBar = (ProgressBar) f3.findViewById(R.id.progressBar); prog_text = (TextView) f3.findViewById(R.id.prog_text); f0 = (TextView) f3.findViewById(R.id.go_app); if (!Settings.canDrawOverlays(this)) { startActivityForResult(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse(new StringBuffer().append("package:").append(getPackageName()).toString())), 4444); } f4 = (EditText) findViewById(R.id.f7); f4.setText(fileUtil.readFile("/storage/emulated/0/Kami")); findViewById(R.id.f8).setOnClickListener(new View.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000010 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000010 r4) { return r4.this$0; } @Override // android.view.View.OnClickListener public void onClick(View view) { this.this$0.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://llua.cn/?mod=cardcheck&id=74075"))); } }); findViewById(R.id.kaiqi).setOnClickListener(new View.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000011 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000011 r4) { return r4.this$0; } @Override // android.view.View.OnClickListener public void onClick(View view) { this.this$0.f5 = MainActivity.f4.getText().toString(); if (this.this$0.f5.length() == 0) { StartGame.showFloatWindow(this.this$0); Toast.makeText(this.this$0, "Holle", 0).show(); } } }); ((Button) findViewById(R.id.reset_im)).setOnClickListener(new View.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000012 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000012 r4) { return r4.this$0; } @Override // android.view.View.OnClickListener public void onClick(View view) { SPUtils.setParam(this.this$0.getApplicationContext(), "app_init_mode", new Boolean(false)); System.exit(0); } }); list = new ArrayList(); adapter = new MyAdapter(this, this, list); listView.setAdapter((ListAdapter) adapter); dialog = new AlertDialog.Builder(this).setView(f3).setCancelable(false).create(); if (app_Operation_mode_root) { dialog.show(); initMain(); } } private void SelectModeBox(Activity activity) { app_Operation_mode_root = ((Boolean) SPUtils.getParam(getApplicationContext(), "app_Operation_mode_root", new Boolean(false))).booleanValue(); app_init_mode = ((Boolean) SPUtils.getParam(getApplicationContext(), "app_init_mode", new Boolean(false))).booleanValue(); if (!app_init_mode) { linearLayouts = new LinearLayout(this); linearLayouts.setOrientation(1); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1); int dp2px = dp2px(this, (float) 24); linearLayouts.setPadding(dp2px, dp2px, dp2px, dp2px); linearLayouts.setLayoutParams(layoutParams); TextView textView = new TextView(this); textView.setTextColor(-16777216); textView.setLayoutParams(new LinearLayout.LayoutParams(-2, -2)); textView.setText("运行环境"); textView.setTextSize(19.0f); textView.setGravity(17); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); ((ViewGroup.MarginLayoutParams) layoutParams2).bottomMargin = dp2px(this, (float) 30); textView.setLayoutParams(layoutParams2); Button button = new Button(this); button.setText("ROOT"); button.setTextSize(14.0f); button.setTextColor(-1); button.setBackgroundColor(Color.parseColor("#1E88E5")); button.setLayoutParams(new LinearLayout.LayoutParams(-1, dp2px(this, (float) 45))); ((ViewGroup.MarginLayoutParams) ((LinearLayout.LayoutParams) button.getLayoutParams())).topMargin = dp2px(this, (float) 10); button.setOnClickListener(new View.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000013 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000013 r4) { return r4.this$0; } @Override // android.view.View.OnClickListener public void onClick(View view) { this.this$0.dialogsShow.dismiss(); System.out.println("ROOT"); MainActivity.app_Operation_mode_root = true; this.this$0.ActivityMain(); } }); Button button2 = new Button(this); button2.setText("框架"); button2.setTextSize(14.0f); button2.setTextColor(-1); button2.setBackgroundColor(Color.parseColor("#1E88E5")); button2.setLayoutParams(new LinearLayout.LayoutParams(-1, dp2px(this, (float) 45))); ((ViewGroup.MarginLayoutParams) ((LinearLayout.LayoutParams) button2.getLayoutParams())).topMargin = dp2px(this, (float) 15); button2.setOnClickListener(new View.OnClickListener(this) { // from class: com.XiaoLian.MainActivity.100000014 private final MainActivity this$0; { this.this$0 = r6; } static MainActivity access$0(AnonymousClass100000014 r4) { return r4.this$0; } @Override // android.view.View.OnClickListener public void onClick(View view) { this.this$0.dialogsShow.dismiss(); System.out.println("框架"); MainActivity.app_Operation_mode_root = false; this.this$0.ActivityMain(); } }); linearLayouts.addView(textView); linearLayouts.addView(button); linearLayouts.addView(button2); dialogs = new AlertDialog.Builder(this); dialogs.setCancelable(false); dialogs.setView(linearLayouts); this.dialogsShow = dialogs.show(); if (this.dialogsShow.getWindow() != null) { WindowManager.LayoutParams attributes = this.dialogsShow.getWindow().getAttributes(); ((ViewGroup.LayoutParams) attributes).width = dp2px(this, (float) 260); this.dialogsShow.getWindow().setAttributes(attributes); this.dialogsShow.getWindow().setBackgroundDrawableResource(17170443); return; } return; } ActivityMain(); } private int dp2px(Context context2, float f) { return (int) ((f * context2.getResources().getDisplayMetrics().density) + 0.5f); } private void RequestPermission() { if (!Settings.canDrawOverlays(this)) { startActivityForResult(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse(new StringBuffer().append("package:").append(getPackageName()).toString())), 4444); } } public void requestPermission() { boolean z = true; if (Build.VERSION.SDK_INT >= 23) { if (checkSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") != 0) { z = false; } if (checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != 0) { z = false; } if (checkSelfPermission("android.permission.RECORD_AUDIO") != 0) { z = false; } if (checkSelfPermission("android.permission.RESTART_PACKAGES") != 0) { z = false; } if (checkSelfPermission("android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND") != 0) { z = false; } if (checkSelfPermission("android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS") != 0) { z = false; } if (checkSelfPermission("android.permission.SYSTEM_ALERT_WINDOW") != 0) { z = false; } if (!z) { requestPermissions(new String[]{"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.RECORD_AUDIO", "android.permission.RESTART_PACKAGES", "android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND", "android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", "android.permission.SYSTEM_ALERT_WINDOW", "android.permission.WRITE_EXTERNAL_STORAGE"}, 102); } } if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) { startActivityForResult(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse(new StringBuffer().append("package:").append(getPackageName()).toString())), 111); } } } 讲解一下这段代码,这个app有什么功能?
10-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值