0

アイテムを挿入しようとしましrecyclerViewたが、アニメーション化に使用するnotifyItemInsertedと、強制的に閉じられ、メッセージは No static method clearInterpolator in recyclerview です。それが何を意味するのかわかりません。助けてくれてありがとう

ここにmainActivtyadapterおよびlogcat

public class MainActivity extends AppCompatActivity {   

DrawerLayout mDrawerLayout;
TextView txtMemoryInfo;
TextView txtMemoryPercent;  
TextView txtMemoryUnit;
LinearLayout layFreeableMemoryInfo;
RecyclerView recyclerAppList;
LinearLayoutManager layoutManager;
RunningAppAdapter runningAppAdapter;
AppBarLayout appBar;
int MemFreeable;
int oldProgValue;
public List<AppInfo> result;
public WaveView wave;
int countItems = 0;

AppCompatButton btnCompatRemove;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overrideFonts();
    setContentView(R.layout.activity_main);
    initToolBar();
    setupViewAndListeners();
    setProgressBarInfo();
    ItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setAddDuration(1000);
    itemAnimator.setRemoveDuration(1000);
    recyclerAppList.setItemAnimator(itemAnimator);
    runningAppAdapter = new RunningAppAdapter(MainActivity.this);
    recyclerAppList.setAdapter(runningAppAdapter);



    new LoadAppsRecyclerView().execute();
}

private class LoadAppsRecyclerView extends AsyncTask<Void, String, Integer> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();            
    }

    @Override
    protected  Integer doInBackground(Void... params) {
        int isCorrect= 0;
        GetRunningAppProcess getProcess = new GetRunningAppProcess(MainActivity.this);

        String launcherName = getProcess.getLauncherName();
        for(int count = 0; count < getProcess.runningAppProcess.size(); count++) {
            final AppInfo appInfo = new AppInfo();

            RunningAppProcessInfo processInfo = getProcess.runningAppProcess.get(count);

            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && processInfo.importanceReasonCode == ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN) {    
                continue;
            }

            try {
                String appPackage = processInfo.processName;
                ApplicationInfo applicationInfo = getProcess.packageManager.getApplicationInfo(appPackage.split(":")[0], 0);
                float totalMemPss = getProcess.getMemTotalPss(processInfo);
                String appName = applicationInfo.loadLabel(getPackageManager()).toString();

                if(applicationInfo.packageName.equals(launcherName)){
                    continue;
                }               
                appInfo.appName = appName;
                appInfo.appPackage = appPackage;
                appInfo.appMemUsed = String.valueOf(totalMemPss) + " MB";
                result.add(appInfo);
                MemFreeable += totalMemPss;
                runOnUiThread(new Runnable() {
                    public void run() {



                        /**********
                        Item inserted here */

                        runningAppAdapter.insertItem( appInfo);


                        /************/


                    }
                });

                countItems++;
                Log.i("count", ""+countItems);
                publishProgress(String.valueOf(MemFreeable));
            } 
            catch (NameNotFoundException e) {

            }
        }           
        //runningAppAdapter = new RunningAppAdapter(result,MainActivity.this);                                  
        return isCorrect;                
    }

    @Override
    protected void onPostExecute(Integer args) {


        ObjectAnimator.ofFloat(layFreeableMemoryInfo, "rotationY", 0,180, 0).setDuration(2000).start();
        Handler handler = new Handler();            
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                int memPercentFreealble = ((MemFreeable) * 100)/1895;
                txtMemoryUnit.setText("%");
                txtMemoryPercent.setText(String.valueOf(memPercentFreealble));                  
            }
        }, 2100);               

    }

    @Override
    protected void onProgressUpdate(String... values) {

        super.onProgressUpdate(values);
        int memPercentFreealble = (((Integer.parseInt(values[0])) * 200))/1895;
        for(int i = oldProgValue; i < memPercentFreealble; i++){
            wave.setProgress(i);
            txtMemoryPercent.setText(values[0]);
            oldProgValue = i;
            appBar.setBackgroundColor(SelectColor.selectIntColor(memPercentFreealble));
        }

    }      

}

アダプタ:

public class RunningAppAdapter extends RecyclerView.Adapter<RunningAppAdapter.ContactViewHolder> {

private List<AppInfo> appList;
public static Context contextMain;
public static Picasso mPicasso;
private boolean[] itemChecks;

public RunningAppAdapter(List<AppInfo> appList,Context context) {
    this.appList = appList;
    RunningAppAdapter.contextMain = context;
    Picasso.Builder builder = new Picasso.Builder(contextMain);
    builder.addRequestHandler(new AppIconRequestHandler(contextMain));
    itemChecks = new boolean [1000];
    Arrays.fill(itemChecks, true);
    mPicasso = builder.build();
}

public RunningAppAdapter(Context context) {
    this.appList = new ArrayList<AppInfo>();
    RunningAppAdapter.contextMain = context;
    Picasso.Builder builder = new Picasso.Builder(contextMain);
    builder.addRequestHandler(new AppIconRequestHandler(contextMain));

    itemChecks = new boolean [1000];
    Arrays.fill(itemChecks, true);
    mPicasso = builder.build();
}

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


public void removeFirstItems(int count) {
    for (int i=0; i<count; i++) 
        appList.remove(0);
    notifyDataSetChanged();
}

public void insertItem(AppInfo object) {
    appList.add(object);  
    notifyItemInserted(getItemCount() - 1);
}


@Override
public void onBindViewHolder(ContactViewHolder appViewHolder, final int position) {


    AppInfo appInfo = appList.get(position);
    appViewHolder.appName.setText(appInfo.appName);
    appViewHolder.appPackage.setText(appInfo.appPackage);
    appViewHolder.appMemUsed.setText(appInfo.appMemUsed);
    appViewHolder.appMemUsed.setOnCheckedChangeListener(null);
    appViewHolder.appMemUsed.setChecked(itemChecks[position]);
    appViewHolder.appMemUsed.setOnCheckedChangeListener(new OnCheckedChangeListener() {         
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                                
            itemChecks[position] = isChecked;
        }
    });
    mPicasso.load(AppIconRequestHandler.SCHEME_APP_ICON + ":" + appInfo.appPackage.split(":")[0]).placeholder(R.drawable.ic_launcher).into(appViewHolder.appDrawable);       
}

@Override
public ContactViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.custom_item_app, viewGroup, false);
        ContactViewHolder app = new ContactViewHolder(itemView);
        return app;

}

public static class ContactViewHolder extends RecyclerView.ViewHolder {

    protected TextView appName;
    protected TextView appPackage;
    protected ImageView appDrawable;
    protected AppCompatCheckBox appMemUsed;
    protected CardView item_card;

    public ContactViewHolder(View v) {
        super(v);

        contextMain = v.getContext();
        appName =  (TextView) v.findViewById(R.id.txtAppName);
        appPackage = (TextView)  v.findViewById(R.id.txtAppPackage);
        appDrawable = (ImageView) v.findViewById(R.id.imgAppIcon);
        appMemUsed = (AppCompatCheckBox) v.findViewById(R.id.chboxFree);
        item_card = (CardView) v.findViewById(R.id.card_view);

        v.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("Click", "Element"+getLayoutPosition() +"click." +appName.getText().toString());
                boolean checkBoxState = !appMemUsed.isChecked();
                appMemUsed.setChecked(checkBoxState);

            }
        });       
    }

} 

}

logcat :

02-08 12:29:40.451: E/AndroidRuntime(2138): FATAL EXCEPTION: main
02-08 12:29:40.451: E/AndroidRuntime(2138): Process: ir.androidnevisha.ramprogress, PID: 2138
02-08 12:29:40.451: E/AndroidRuntime(2138): java.lang.NoSuchMethodError: No static method clearInterpolator(Landroid/view/View;)V in class Landroid/support/v4/animation/AnimatorCompatHelper; or its super classes (declaration of 'android.support.v4.animation.AnimatorCompatHelper' appears in /data/app/ir.androidnevisha.ramprogress-1/base.apk)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:513)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.DefaultItemAnimator.animateAdd(DefaultItemAnimator.java:216)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.SimpleItemAnimator.animateAppearance(SimpleItemAnimator.java:105)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView.animateAppearance(RecyclerView.java:3037)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView.access$800(RecyclerView.java:144)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView$4.processAppeared(RecyclerView.java:421)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.ViewInfoStore.process(ViewInfoStore.java:213)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2931)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1445)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:144)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:282)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.view.Choreographer.doCallbacks(Choreographer.java:580)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.view.Choreographer.doFrame(Choreographer.java:549)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.os.Handler.handleCallback(Handler.java:739)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.os.Looper.loop(Looper.java:135)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at android.app.ActivityThread.main(ActivityThread.java:5254)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at java.lang.reflect.Method.invoke(Native Method)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at java.lang.reflect.Method.invoke(Method.java:372)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-08 12:29:40.451: E/AndroidRuntime(2138):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
4

1 に答える 1

1

Recycleriew を導入する前に、長い間書いておくべきだったと思います。同時に互換パッケージを更新する必要があります。

例えば:

compile 'com.android.support:appcompat-v7:23.4.0'

compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:appcompat-v7:24.2.0'

バージョン番号の後ろのセミコロンに注意してください。

于 2016-08-25T06:27:33.700 に答える