应用程序在选项卡式片段之间滑动时崩溃

时间:2017-08-06 13:07:18

标签: android android-fragments

我尝试在片段中实现Recyclerview。它的工作正常,但如果我在我的第一个碎片和我的第二个碎片之间快速滑动它的崩溃 - >看视频。这是错误日志:

08-06 14:59:06.346 4027-4103/? E/HwLauncher: SettingsEx , no such field.
08-06 14:59:06.358 4859-4885/? E/PackageLogInfoManager: checkPackageLogState, cr: android.app.ContextImpl$ApplicationContentResolver@d696c32, packageNames: null
08-06 14:59:06.388 2416-2416/? E/HAL: load: id=gralloc != hmi->id=gralloc
08-06 14:59:06.437 2416-2416/? E/HAL: load: id=gralloc != hmi->id=gralloc
08-06 14:59:06.445 3069-3378/? E/InputReader: QEEXO fs_touch_up NULL, not calling FingerSense
08-06 14:59:06.575 2416-2416/? E/hwcomposer: setGpuBoost:228: Can't open /sys/class/devfreq/gpufreq/max_freq: Permission denied
08-06 14:59:06.935 2416-2416/? E/HAL: load: id=gralloc != hmi->id=gralloc
08-06 14:59:09.525 3069-3385/? E/HsmCoreServiceImpl: onTransact in code is: 102
08-06 14:59:10.708 14240-14240/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@data@com.google.android.gms@app_chimera@m@0000000a@DynamiteLoader_GmsCore_prodmnc_xhdpi_release.apk@classes.dex: Permission denied
08-06 14:59:10.841 14245-14245/? E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm/data@data@com.google.android.gms@app_chimera@m@0000000b@GoogleCertificates_GmsCore_prodmnc_xhdpi_release.apk@classes.dex: Permission denied
08-06 14:59:11.285 3069-4006/? E/HsmCoreServiceImpl: onTransact in code is: 102

这是我的片段:

public class Events_Fragment extends Fragment {
private static final String TAG = "RecyclerViewFragment";
private static String url = "http://partypeople.bplaced.net/lola.php";
private static final int DATASET_COUNT = 60;
ArrayList<HashMap<String, String>> testdata;

protected RecyclerView mRecyclerView;
protected Customlist_Events mAdapter;

protected String[] mDataset;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addData();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.events, container, false);
    rootView.setTag(TAG);
    testdata = new ArrayList<>();
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);


    LinearLayoutManager lin = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView.setLayoutManager(lin);
    mRecyclerView.setHasFixedSize(true);
    //new FetchDataTask().execute();
    mAdapter = new Customlist_Events(mDataset);
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);
    Toast.makeText(getActivity(),"Countdown finished",Toast.LENGTH_LONG).show();
    return rootView;
}


public void addData(){

    mDataset = new String[DATASET_COUNT];
    for (int i = 0; i < DATASET_COUNT; i++) {

        mDataset[i] = "name";

    }
}

这是我的布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="250dp"/>
    </RelativeLayout>
    </ScrollView>
</LinearLayout>

这是我的自定义适配器:

public class Customlist_Events extends RecyclerView.Adapter<Customlist_Events.ViewHolder> {
private static final String TAG = "CustomAdapter";

private String[] mDataSet;

/**
 * Provide a reference to the type of views that you are using (custom ViewHolder)
 */
public static class ViewHolder extends RecyclerView.ViewHolder {
    private final TextView textView;

    public ViewHolder(View v) {
        super(v);
        // Define click listener for the ViewHolder's View.
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(TAG, "Element " + getAdapterPosition() + " clicked.");
            }
        });
        textView = (TextView) v.findViewById(R.id.textView);
    }

    public TextView getTextView() {
        return textView;
    }
}

/**
 * Initialize the dataset of the Adapter.
 *
 * @param dataSet String[] containing the data to populate views to be used by RecyclerView.
 */
public Customlist_Events(String[] dataSet) {
    mDataSet = dataSet;
}

// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    // Create a new view.
    View v = LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.text_row_item, viewGroup, false);

    return new ViewHolder(v);
}

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
    Log.d(TAG, "Element " + position + " set."+mDataSet[position]);

    // Get element from your dataset at this position and replace the contents of the view
    // with that element

    viewHolder.getTextView().setText(mDataSet[position]);
}

// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {

    return mDataSet.length;
}

}

我试图在我的Recyclerview中显示哪些数据无关紧要。 此致

0 个答案:

没有答案