滚动视图是否可以分段工作? [英] Does scrollview work in fragments?

查看:65
本文介绍了滚动视图是否可以分段工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个employeeList片段,该片段在访问时使应用程序崩溃.代码中没有波浪线,堆栈跟踪中也没有任何警报.我有一种预感,scrollView可能是造成这种情况的原因.这是代码

I have an employeeList fragment which upon access crashes the app. There are no squiggly lines in code, neither any alarms in the stack trace. I have a hunch that scrollView might be causing this. Here's the code

ManageFragment.java

package com.teslaqubitsins.fasih.teslahcm;


import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import java.util.ArrayList;

import static android.content.Context.MODE_PRIVATE;
import static android.database.sqlite.SQLiteDatabase.openOrCreateDatabase;


public class ManageFragment extends Fragment {

    EmployeeDatasource mEmployeeDatasource;
    View rootView;

    public ManageFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        rootView = inflater.inflate(R.layout.fragment_manage, container, false);
        mEmployeeDatasource = new EmployeeDatasource(getActivity());
        final ArrayList<Employee> employeeArrayList = mEmployeeDatasource.getList();
        ListView mListView = (ListView) getActivity().findViewById(R.id.employeeList_listView);
        EmployeeAdapter mEmployeeAdapter = new EmployeeAdapter(this.getActivity(), R.layout.row_employee_list, employeeArrayList);
        mListView.setAdapter(mEmployeeAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
              public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                EmployeeDetailFragment detailedemployee = new EmployeeDetailFragment();
                Employee item = employeeArrayList.get(i);
                EmployeeDetailFragment.mEmployee = item;
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.replace(R.id.content, detailedemployee);
                ft.addToBackStack(null);
                ft.commit();

            }
        });
        return rootView;
    }
}

fragment_manage.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.teslaqubitsins.fasih.teslahcm.ManageFragment">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/employeeList_listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </ListView>

    </LinearLayout>

</FrameLayout>

row_employee_list.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="2dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="7"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/row_employee_imageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                android:src="@drawable/ic_stub" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="3"
            android:orientation="vertical"
            android:padding="5dp">

            <TextView
                android:id="@+id/row_employee_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:maxLines="1"
                android:text="Employee Name"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/row_employee_salary"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:maxLines="1"
                android:text="120 PKR" />
        </LinearLayout>
    </LinearLayout>

</FrameLayout>

请有人帮我解决问题.

日志

04-24 15:17:31.223  1314: 1314 E/         ]                                                                          Couldn't opendir /data/app/vmdl1759858640.tmp: No such file or

directory 04-24 15:17:32.773 2184-2184/com.google.android.googlequicksearchbox:search W/LocationOracle: Starting background requests 04-24 15:17:33.123 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 04-24 15:17:33.124 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 04-24 15:17:35.478 2048-2960/com.google.android.gms.persistent I/GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=android.intent.action.BOOT_COMPLETED}] 04-24 15:17:36.013 2048-2986/com.google.android.gms.persistent I/GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction android.intent.action.BOOT_COMPLETED 04-24 15:17:36.533 2048-2990/com.google.android.gms.persistent I/GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=com.google.android.location.internal.server.ACTION_RESTARTED}] 04-24 15:17:36.575 2048-2365/com.google.android.gms.persistent I/GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=com.google.android.location.reporting.PHENOTYPE_FLAGS_CHANGED}] 04-24 15:17:37.325 3106-3106/? W/dex2oat: /system/bin/dex2oat
--runtime-arg -classpath --runtime-arg & --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2,-lock_add,-popcnt
--runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/user/0/com.google.android.gms/app_fb/f.apk --oat-fd=51 --oat-location=/data/user/0/com.google.android.gms/app_fb/f.dex --compiler-filter=speed 04-24 15:17:37.325 3106-3106/? I/dex2oat: /system/bin/dex2oat
--dex-file=/data/user/0/com.google.android.gms/app_fb/f.apk --oat-fd=51 --oat-location=/data/user/0/com.google.android.gms/app_fb/f.dex --compiler-filter=speed 04-24 15:17:37.780 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 04-24 15:17:37.780 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 04-24 15:17:37.920 2048-2986/com.google.android.gms.persistent I/GCoreUlr: GMS FLP location and AR updates requested: {"description":"stationary","newRequest":true,"samplePeriodMs":2160000,"sampleReason":"stationary","sampleSource":"internal","timestampMs":1493029056848} 04-24 15:17:38.057 2048-2986/com.google.android.gms.persistent I/GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction com.google.android.location.internal.server.ACTION_RESTARTED 04-24 15:17:38.064 2048-2986/com.google.android.gms.persistent I/GCoreUlr: WorldUpdater:com.google.android.location.internal.server.ACTION_RESTARTED: Ensuring that reporting is active for [account#7#] 04-24 15:17:38.069 2048-2986/com.google.android.gms.persistent I/GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction com.google.android.location.reporting.PHENOTYPE_FLAGS_CHANGED 04-24 15:17:38.103 2048-2986/com.google.android.gms.persistent I/GCoreUlr: WorldUpdater:com.google.android.location.reporting.PHENOTYPE_FLAGS_CHANGED: Ensuring that reporting is active for [account#7#] 04-24 15:17:38.430 2048-2048/com.google.android.gms.persistent E/ActivityThread: Service com.google.android.location.places.service.PlaceDetectionAsyncService has leaked IntentReceiver amth@cd0bee8 that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                                 android.app.IntentReceiverLeaked: Service com.google.android.location.places.service.PlaceDetectionAsyncService has leaked IntentReceiver amth@cd0bee8 that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                                     at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1159)
                                                                                     at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:946)
                                                                                     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1302)
                                                                                     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1282)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at amrb.run(:com.google.android.gms:4414)
                                                                                     at android.os.Handler.handleCallback(Handler.java:751)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                     at android.os.Looper.loop(Looper.java:154)
                                                                                     at android.os.HandlerThread.run(HandlerThread.java:61) 04-24 15:17:38.545 2048-2048/com.google.android.gms.persistent E/ActivityThread: Service com.google.android.location.places.service.PlaceDetectionAsyncService has leaked IntentReceiver amth@b6a0290 that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                                 android.app.IntentReceiverLeaked: Service com.google.android.location.places.service.PlaceDetectionAsyncService has leaked IntentReceiver amth@b6a0290 that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                                                     at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1159)
                                                                                     at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:946)
                                                                                     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1302)
                                                                                     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1282)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:593)
                                                                                     at amrb.run(:com.google.android.gms:4414)
                                                                                     at android.os.Handler.handleCallback(Handler.java:751)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                     at android.os.Looper.loop(Looper.java:154)
                                                                                     at android.os.HandlerThread.run(HandlerThread.java:61) 04-24 15:17:42.411 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation() 04-24 15:17:42.411 2048-2298/com.google.android.gms.persistent W/GCoreFlp: No location to return for getLastLocation()

MainActivity.java

package com.teslaqubitsins.fasih.teslahcm;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView mTextMessage;

    private static final String TAG = MainActivity.class.getSimpleName();
    private BottomNavigationView bottomNavigation;
    private Fragment fragment;
    private FragmentManager fragmentManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
        bottomNavigation = (BottomNavigationView)findViewById(R.id.navigation1);
        bottomNavigation.inflateMenu(R.menu.menu);
        fragmentManager = getSupportFragmentManager();
        bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        int id = item.getItemId();
        switch (id){
        case R.id.bb_menu_home:
        fragment = new HomeFragment();
        break;
        case R.id.bb_menu_contact:
        fragment = new ContactFragment();
        break;
        case R.id.bb_menu_manage:
        fragment = new ManageFragment();
        break;
        case R.id.bb_menu_queries:
        fragment = new QueriesFragment();
        break;
        case R.id.bb_menu_careers:
        fragment = new CareersFragment();
        break;
            default:
            fragment = new HomeFragment();
        }
final FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.content, fragment).commit();
        return true;
        }
        });
        }

}

推荐答案

替换:

FragmentTransaction ft = getFragmentManager().beginTransaction();

使用:

FragmentTransaction ft = getChildFragmentManager().beginTransaction();

这篇关于滚动视图是否可以分段工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆