CoverFlow'选择项目'

时间:2017-08-03 13:10:08

标签: android coverflow

我对android studio知道(我对c#和c ++有一些有限的知识)并且基本上已经学习了,到目前为止一直工作正常。我正在使用一个封面流程示例,在经过大量调查之后,我无法确定在哪里以及如何设置等同于点击监听器'。本节的目的是根据所选项目选择一个随机数。

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import java.util.ArrayList;

import it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow;

/**
 * A simple {@link Fragment} subclass.
 */
public class FitnessDiary_Fragment2 extends Fragment {

    Main2Activity mainActivity;

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


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mood_diary_, container, false);

        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.mooddiary_pagename);

        mainActivity = (Main2Activity)getActivity();
        mainActivity.coverFlow = (FeatureCoverFlow) view.findViewById(R.id.coverflow);

        settingDummyData();



        mainActivity.adapter = new CoverFlowAdapter(mainActivity, mainActivity.games);
        mainActivity.coverFlow.setAdapter(mainActivity.adapter);

        // Inflate the layout for this fragment
        return view;
    }

    private void settingDummyData() {
        mainActivity.games = new ArrayList<>();
        mainActivity.games.add(new Game(R.drawable.ic_temp, 
        "replacement1"));
        mainActivity.games.add(new Game(R.drawable.ic_temp, 
        "replacement2"));
        mainActivity.games.add(new Game(R.drawable.ic_temp, 
        "replacement3"));
        mainActivity.games.add(new Game(R.drawable.ic_temp, 
         "replacement4"));
    }

}

由于片段工作,这是主要的活动&#39;上面的代码引用了我的怀疑是我需要这段代码是我的下面部分,但我不确定。

    import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;
import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker;
import com.ignitec.xxxxx.coverflow.CoverFlowAdapter;
import com.ignitec.xxxxx.coverflow.Game;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow;

public class Main2Activity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    public FeatureCoverFlow coverFlow;
    public CoverFlowAdapter adapter;
    public ArrayList<Game> games;

提前致谢!

1 个答案:

答案 0 :(得分:0)

事实证明它就像创建一个'onScrollPositionListener'一样简单,遗憾的是我花了一天的时间才弄明白:)。

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mood_diary_, container, false);

        ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.mooddiary_pagename);

        mainActivity = (Main2Activity)getActivity();
        mainActivity.coverFlow = (FeatureCoverFlow) view.findViewById(R.id.coverflow);

        settingDummyData();

        mainActivity.adapter = new CoverFlowAdapter(mainActivity, mainActivity.games);
        mainActivity.coverFlow.setAdapter(mainActivity.adapter);


        mainActivity.coverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //TODO CoverFlow item clicked
            }
        });

        mainActivity.coverFlow.setOnScrollPositionListener(new FeatureCoverFlow.OnScrollPositionListener() {
            @Override
            public void onScrolledToPosition(int position) {
                Log.e("Position----->", "" + position);
            }

            @Override
            public void onScrolling() {
                //TODO CoverFlow began scrolling
            }
        });



        // Inflate the layout for this fragment
        return view;
    }