我正在尝试编辑listView上的行以包含复选框.我的listView项的布局在这里定义:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dip"
>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="5dip"
android:scaleType="center"
android:contentDescription="@string/desc"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<TextView
android:id="@+id/tvName"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
<TextView
android:id="@+id/tvPack"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
<Checkbox
android:id="@+id/addCheckbox"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后我有一个自定义适配器,如下所示:
package com.example.awesomefilebuilderwidget;
IMPORTS
public class AppInfoAdapter extends BaseAdapter implements Filterable {
private Context mContext;
private List<ApplicationInfo> mListAppInfo;
private PackageManager mPackManager;
private List<ApplicationInfo> originalListAppInfo;
private Filter filter;
public AppInfoAdapter(Context c, List<ApplicationInfo> listApp, …Run Code Online (Sandbox Code Playgroud) 在我的小部件中,我不断收到此错误:
11-02 09:35:10.613: D/D&D(1557): onCreate called
11-02 09:35:10.933: E/JavaBinder(1557): !!! FAILED BINDER TRANSACTION !!!
11-02 09:35:10.933: D/AppInfoAdapter(1557): top
Run Code Online (Sandbox Code Playgroud)
无论我做什么(我尝试减小位图大小,使位图静态,注释掉部分编码以查看错误所在(顺便说一句,这根本没有帮助)),我总是得到这个错误。这个错误导致的原因是它使我的用户安装的应用程序的列表视图根本不显示在滑动抽屉中(它只是空白)。我所有的链接和其他课程都工作得很好。(但我的 listView 是整个小部件的中心部分和主要功能。)
我现在不知所措,所以我只想发布三个可疑的课程,我已经得出结论,这是源于(因为所有其他课程都工作正常)。
请注意,一些代码被注释掉了(例如拖放功能的编码,因为我的真实设备不支持蜂窝。但是,当我的 listView 再次开始工作时,我将实现该代码)
AppInfoAdapter.java:
package com.example.awesomefilebuilderwidget;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
public class AppInfoAdapter extends BaseAdapter implements Filterable {
private Context …Run Code Online (Sandbox Code Playgroud)