片段中的Listview OnClick新活动 - “不幸的是,App已停止”

时间:2018-02-12 14:02:49

标签: android

我正在为旅游景点做VR全景视图,我用listview创建了一个Tab布局, 在列表视图中,有一个项目可以显示VR视图出现的新活动,但是当我尝试单击该项目时,会出现一个消息"不幸的是,ATDRAG APP已停止"当我尝试创建新的活动时,它可以工作,但是当我使用VR View活动时,我再次收到了这个消息。我该怎么办?那个活动是碎片。我会在这里列出代码。提前谢谢!

logcat的

02-08 11:23:02.243 10970-10970/? E/libprocessgroup: failed to make and chown /acct/uid_10060: Read-only file system
02-08 11:23:02.991 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 11:23:03.030 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 11:23:21.181 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 11:23:21.341 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:09.976 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:10.178 10970-10988/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:20.664 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:20.709 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:26.492 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:22:26.753 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:25:08.235 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:25:08.544 10970-11169/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:25:15.449 10970-11194/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:25:15.463 10970-11194/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:49:31.605 10970-11194/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
02-08 13:49:31.947 10970-11194/com.google.devrel.vrviewapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf

MainActivity 标签布局

package com.google.devrel.vrviewapp;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        assert tabLayout != null;
        tabLayout.addTab(tabLayout.newTab().setText(R.string.welcome));
        tabLayout.addTab(tabLayout.newTab().setText(R.string.venue));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        final PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {

            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 0:
                        return new WelcomeFragment();
                    case 1:
                        return new ttsd();
                }
                return null;
            }

            @Override
            public int getCount() {
                return 2;
            }
        };
        assert viewPager != null;
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    public void refreshNow() {
        finish();
        overridePendingTransition(0,0);
        startActivity(getIntent());
        overridePendingTransition(0,0);
    }
}

ttd Listview Onclick项目

package com.google.devrel.vrviewapp;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.content.Intent;
import android.widget.AdapterView;

public class ttsd extends Fragment {


    public ttsd() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.ttsd, container, false);
        // Inflate the layout for this fragment
        String[] awayStrings = {
                "Tubbataha Reef",
                "San Agustin Church",
                "Mayon Volcano",
                "Malapascua Island",
                "Puerto Galera",
                "Puerto Princesa Undergound River",
                "Donsol",
                "Banaue Rice Terraces",

        };

        ListView lv = (ListView) view.findViewById(R.id.listView2);

        ArrayAdapter<String> lva = new ArrayAdapter<String>(
                getActivity(), android.R.layout.simple_list_item_1, awayStrings);
        lv.setAdapter(lva);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if(position==0) {
                    Intent myintent = new Intent(view.getContext(), toptourist2.class);
                    startActivityForResult(myintent, 0);
                }
            }
        });

        final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.fragment_away);

        mSwipeRefreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        ((MainActivity) getActivity()).refreshNow();
                        Toast.makeText(getContext(), "Refresh Layout working", Toast.LENGTH_LONG).show();
                    }
                }
        );

        return view;
    }
}

toptourist1 vr视图

package com.google.devrel.vrviewapp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.vr.sdk.widgets.pano.VrPanoramaView;


public class toptourist1 extends Fragment {

    private VrPanoramaView panoWidgetView;
    private ImageLoaderTask backgroundImageLoaderTask;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v =  inflater.inflate(R.layout.activity_toptourist1, container,false);
        panoWidgetView = (VrPanoramaView) v.findViewById(R.id.pano_view);
        return v;
    }

    @Override
    public void onPause() {
        panoWidgetView.pauseRendering();
        super.onPause();
    }

    @Override
    public void onResume() {
        panoWidgetView.resumeRendering();
        super.onResume();
    }

    @Override
    public void onDestroy() {

        panoWidgetView.shutdown();
        super.onDestroy();
    }

    private synchronized void loadPanoImage() {
        ImageLoaderTask task = backgroundImageLoaderTask;
        if (task != null && !task.isCancelled()) {
            task.cancel(true);
        }

        VrPanoramaView.Options viewOptions = new VrPanoramaView.Options();
        viewOptions.inputType = VrPanoramaView.Options.TYPE_STEREO_OVER_UNDER;

        String panoImageName = "sample_converted.jpg";

        task = new ImageLoaderTask(panoWidgetView, viewOptions, panoImageName);
        task.execute(getActivity().getAssets());
        backgroundImageLoaderTask = task;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        loadPanoImage();
    }

}

1 个答案:

答案 0 :(得分:0)

这似乎你想要从设备打开panoImageName.jpg并且你没有读取SD卡的权限,所以将这一行添加到你的Manifest。

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

for api&gt; 21你必须拨打这一行

ActivityCompat.requestPermissions(LoginActivity.this,
            new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
            1);

希望它的帮助