From 22fe5a0fdc12a6eefc6c060dd6f27f8645556c8d Mon Sep 17 00:00:00 2001 From: mmk2410 Date: Mon, 30 Mar 2015 23:41:38 +0200 Subject: [PATCH] Added Recycler List --- .gitignore | 1 + app/app.iml | 11 ++-- app/build.gradle | 3 +- .../morseconverter/MainActivity.java | 5 +- .../morseconverter/MyAdapter.java | 53 +++++++++++++++++++ .../writtenMorseListFragment.java | 40 ++++++++++++++ app/src/main/res/layout/codeview.xml | 12 +++++ .../layout/fragment_written_morse_list.xml | 13 +++++ app/src/main/res/values/strings.xml | 3 ++ 9 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java create mode 100644 app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java create mode 100644 app/src/main/res/layout/codeview.xml create mode 100644 app/src/main/res/layout/fragment_written_morse_list.xml diff --git a/.gitignore b/.gitignore index 5be8779..1756639 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ proguard/ # IntelliJ IDEA Files *.iml +app/app.iml diff --git a/app/app.iml b/app/app.iml index 44d78b8..84fb8dd 100644 --- a/app/app.iml +++ b/app/app.iml @@ -85,12 +85,13 @@ - - - - - + + + + + + diff --git a/app/build.gradle b/app/build.gradle index bd75795..60dc879 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,8 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' - compile 'it.neokree:MaterialNavigationDrawer:1.3' + compile 'it.neokree:MaterialNavigationDrawer:1.3.3' compile 'com.android.support:cardview-v7:21.0.3' compile 'com.android.support:support-v4:21.0.3' + compile 'com.android.support:recyclerview-v7:21.0.+' } diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java b/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java index 3b088f0..7cc9f99 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/MainActivity.java @@ -40,7 +40,7 @@ import it.neokree.materialnavigationdrawer.elements.MaterialSection; public class MainActivity extends MaterialNavigationDrawer { //Declaring the Material Sections - private MaterialSection writtenMorse, normalMorse, about; + private MaterialSection writtenMorse, normalMorse, writtenMorseList, about; //The MaterialNavigationDrawer init() methode replaces the normal onCreate() methode @Override @@ -49,11 +49,14 @@ public class MainActivity extends MaterialNavigationDrawer { //Declaring the Material Sections writtenMorse = this.newSection("writtenMorse", new MainFragment()); normalMorse = this.newSection(res.getString(R.string.normalMorse), new MorseFragment()); + writtenMorseList = this.newSection("writtenMorse Codes", new writtenMorseListFragment()); //TODO rename about = this.newSection(res.getString(R.string.about), new AboutFragment()); //Adding the Sections this.addSection(writtenMorse); this.addSection(normalMorse); this.addDivisor(); + this.addSection(writtenMorseList); + this.addDivisor(); this.addSection(about); //set drawer image this.setDrawerHeaderImage(this.getResources().getDrawable(R.drawable.feature_graphics)); diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java b/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java new file mode 100644 index 0000000..dbe687c --- /dev/null +++ b/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java @@ -0,0 +1,53 @@ +package de.marcelkapfer.morseconverter; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +/** + * Created by mmk on 3/30/15. + */ +public class MyAdapter extends RecyclerView.Adapter { + private String[] mDataset; + + public static class ViewHolder extends RecyclerView.ViewHolder { + // each data item is just a string in this case + public TextView mTextView; + public ViewHolder(View v) { + super(v); + mTextView = (TextView) v.findViewById(R.id.codefield); + } + + public TextView getTextView() { + return mTextView; + } + } + + public MyAdapter(String[] myDataset) { + mDataset = myDataset; + } + + @Override + public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, + int viewType) { + // create a new view + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.codeview, parent, false); + ViewHolder vh = new ViewHolder(v); + return vh; + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + holder.mTextView.setText(mDataset[position]); + + } + + @Override + public int getItemCount() { + return mDataset.length; + } +} diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java b/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java new file mode 100644 index 0000000..eb58dd9 --- /dev/null +++ b/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java @@ -0,0 +1,40 @@ +package de.marcelkapfer.morseconverter; + +import android.app.FragmentManager; +import android.app.FragmentTransaction; +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; + + +public class writtenMorseListFragment extends Fragment { + + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + private String[] myDataset = {"test1","test2","test3","test1","test2","test3","test1","test2","test3","test1","test2","test3"}; + private static final String TAG = "RecyclerViewFragment"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ + View rootView = inflater.inflate(R.layout.fragment_written_morse_list, container, false); + rootView.setTag(TAG); + mRecyclerView = (RecyclerView) rootView.findViewById(R.id.wm_recycler); + mRecyclerView.setHasFixedSize(true); + mLayoutManager = new LinearLayoutManager(getActivity()); + mRecyclerView.setLayoutManager(mLayoutManager); + mAdapter = new MyAdapter(myDataset); + mRecyclerView.setAdapter(mAdapter); + return rootView; + } + +} diff --git a/app/src/main/res/layout/codeview.xml b/app/src/main/res/layout/codeview.xml new file mode 100644 index 0000000..353586e --- /dev/null +++ b/app/src/main/res/layout/codeview.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_written_morse_list.xml b/app/src/main/res/layout/fragment_written_morse_list.xml new file mode 100644 index 0000000..da41363 --- /dev/null +++ b/app/src/main/res/layout/fragment_written_morse_list.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a9b203b..800dab5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,4 +57,7 @@ SHARE COPY + + + Hello blank fragment