com.kogitune.prelollipoptransition.fragment.ListViewFragment.java Source code

Java tutorial

Introduction

Here is the source code for com.kogitune.prelollipoptransition.fragment.ListViewFragment.java

Source

/*
 * Copyright (C) 2015 takahirom
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.kogitune.prelollipoptransition.fragment;

import android.content.Intent;
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 android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.kogitune.activity_transition.ActivityTransitionLauncher;
import com.kogitune.prelollipoptransition.ListViewActivity;
import com.kogitune.prelollipoptransition.R;
import com.kogitune.prelollipoptransition.SubActivity;

public class ListViewFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_list_view, container, false);

        final ListView listView = (ListView) inflate.findViewById(R.id.list);
        listView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return 10;
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                return inflater.inflate(R.layout.list_row, parent, false);
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final Intent intent = new Intent(getContext(), SubActivity.class);
                ActivityTransitionLauncher.with(getActivity()).from(view.findViewById(R.id.image)).launch(intent);
            }
        });
        return inflate;
    }

}