Added Recycler List

This commit is contained in:
mmk2410 2015-03-30 23:41:38 +02:00
parent 8104b286d3
commit 22fe5a0fdc
9 changed files with 134 additions and 7 deletions

1
.gitignore vendored
View file

@ -30,3 +30,4 @@ proguard/
# IntelliJ IDEA Files
*.iml
app/app.iml

View file

@ -85,12 +85,13 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="android-ui-1.2" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="MaterialNavigationDrawer-1.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="MaterialNavigationDrawer-1.3.3" level="project" />
<orderEntry type="library" exported="" name="material-ripple-1.0.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
</component>
</module>

View file

@ -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.+'
}

View file

@ -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));

View file

@ -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<MyAdapter.ViewHolder> {
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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,12 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="64dp">
<TextView
android:id="@+id/codefield"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/hello_world"
android:gravity="center_vertical"/>
</FrameLayout>

View file

@ -0,0 +1,13 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:orientation="vertical"
android:scrollbars="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/wm_recycler"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View file

@ -57,4 +57,7 @@
<!--Output Text Buttons-->
<string name="button_share">SHARE</string>
<string name="button_copy">COPY</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>