brazole.com.secondtask.TabFragmentListView.java Source code

Java tutorial

Introduction

Here is the source code for brazole.com.secondtask.TabFragmentListView.java

Source

package brazole.com.secondtask;

import android.content.Intent;
import android.os.Bundle;
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.ListView;

import com.melnykov.fab.FloatingActionButton;
import com.melnykov.fab.ScrollDirectionListener;

import java.util.List;
import brazole.com.secondtask.adapters.ListViewAdapter;

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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.
 *
 * android fragment with listview
 */

public class TabFragmentListView extends Fragment {

    private List<Issue> mIssueList;
    private static final String TAG = "ListViewFragment";
    private Intent mIntent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIssueList = CrudIssue.getAllIssues();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.tab_fragment_list_view, container, false);
        rootView.setTag(TAG);
        ListView mListView = (ListView) rootView.findViewById(R.id.lvMain);
        ListViewAdapter mListViewAdapter = new ListViewAdapter(getActivity(), mIssueList);
        mListView.setAdapter(mListViewAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                // Get Clicked item value and open detail activity
                mIntent = new Intent(getActivity(), SavedProblemActivity.class);
                mIntent.putExtra("issueId", mIssueList.get(position).getId());
                startActivity(mIntent);
            }
        });

        // fab show / hide
        final FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
        fab.attachToListView(mListView, new ScrollDirectionListener() {
            @Override
            public void onScrollDown() {
                fab.show();
            }

            @Override
            public void onScrollUp() {
                fab.hide();
            }
        });

        return rootView;
    }

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save currently selected layout manager.
        super.onSaveInstanceState(savedInstanceState);
    }
}