Created
August 31, 2018 23:18
-
-
Save mtali/d60b732bb1d99c6360b4687153eb793f to your computer and use it in GitHub Desktop.
Fixing a bug for a friend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.goodluck.unishop1; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import java.util.ArrayList; | |
@SuppressWarnings("FieldCanBeLocal") | |
public class AllItemsFragment extends Fragment { | |
private RecyclerView recyclerView; | |
private AllItemsListAdapter mAdapter; | |
private ArrayList<AbstractModel> models = new ArrayList<>(); | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
// Inflate the layout | |
View view = inflater.inflate(R.layout.fragment_all_items, container, false); | |
// Populate initial sample data to models list | |
populateData(); | |
// Initialize the adapter | |
mAdapter = new AllItemsListAdapter(getContext(), models); | |
// Create a LinearLayoutManager for vertical scrolling of the content | |
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); | |
// Get the reference to recycler view as defined on your fragment layout | |
recyclerView = view.findViewById(R.id.recycler_view); | |
// Finally hookup recycler view with :- | |
// 1. Layout manager | |
// 2. Adapter | |
// 3. Fixed size property (For performance) | |
recyclerView.setLayoutManager(layoutManager); | |
recyclerView.setAdapter(mAdapter); | |
recyclerView.setHasFixedSize(true); | |
// Return the created view | |
return view; | |
} | |
private void populateData() { | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.arduino)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.arduinomega)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.arduinonano)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.arduinorth)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.arduinouno)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.bluetoothmodule)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.breadboard)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.gsmmodule)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.ifemalefemale)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.imalefemale)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.lcdfourblue)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.lcdfourgreen)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.rasp)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.raspberry)); | |
models.add(new AbstractModel("One set UNO R3 (CH340G) MEGA328P for Arduino UNO R3 with case USB Cable ATMEGA328P-AU Development board", "US $ 17.5", R.drawable.simnine)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment