forked from github/wulkanowy-mirror
Add RecyclerView in marks
This commit is contained in:
parent
96bf42be33
commit
13e5b69e10
@ -31,5 +31,8 @@ dependencies {
|
|||||||
compile 'com.android.support:design:25.3.1'
|
compile 'com.android.support:design:25.3.1'
|
||||||
compile 'com.android.support:support-vector-drawable:25.3.1'
|
compile 'com.android.support:support-vector-drawable:25.3.1'
|
||||||
compile 'com.android.support:support-v4:25.3.1'
|
compile 'com.android.support:support-v4:25.3.1'
|
||||||
|
compile 'com.android.support:recyclerview-v7:25.3.1'
|
||||||
|
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@android:style/Theme.DeviceDefault">
|
android:theme="@style/Theme.AppCompat">
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.started.StartedActivity"
|
android:name=".activity.started.StartedActivity"
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
|
@ -1,62 +1,56 @@
|
|||||||
package io.github.wulkanowy.activity.dashboard.marks;
|
package io.github.wulkanowy.activity.dashboard.marks;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.GridView;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.squareup.picasso.Picasso;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
|
|
||||||
public class ImageAdapter extends BaseAdapter {
|
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public ImageAdapter(Context c) {
|
private Context context;
|
||||||
this.mContext = c;
|
private ArrayList<String> lista;
|
||||||
|
|
||||||
|
public ImageAdapter(Context context, ArrayList<String> lista) {
|
||||||
|
this.lista = lista;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
@Override
|
||||||
return mThumbIds.length;
|
public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||||
|
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout, viewGroup, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getItem(int position) {
|
@Override
|
||||||
return null;
|
public void onBindViewHolder(ImageAdapter.ViewHolder viewHolder, int i) {
|
||||||
|
|
||||||
|
viewHolder.tv_android.setText(lista.get(i));
|
||||||
|
Picasso.with(context).load(R.drawable.sample_0).into(viewHolder.img_android);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int position) {
|
@Override
|
||||||
return 0;
|
public int getItemCount() {
|
||||||
|
return lista.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new ImageView for each item referenced by the Adapter
|
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
private TextView tv_android;
|
||||||
ImageView imageView;
|
private ImageView img_android;
|
||||||
if (convertView == null) {
|
public ViewHolder(View view) {
|
||||||
// if it's not recycled, initialize some attributes
|
super(view);
|
||||||
imageView = new ImageView(mContext);
|
|
||||||
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
|
tv_android = (TextView)view.findViewById(R.id.tv_android);
|
||||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
img_android = (ImageView) view.findViewById(R.id.img_android);
|
||||||
imageView.setPadding(8, 8, 8, 8);
|
|
||||||
} else {
|
|
||||||
imageView = (ImageView) convertView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imageView.setImageResource(mThumbIds[position]);
|
|
||||||
return imageView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// references to our images
|
}
|
||||||
private Integer[] mThumbIds = {
|
|
||||||
R.drawable.sample_2, R.drawable.sample_3,
|
|
||||||
R.drawable.sample_4, R.drawable.sample_5,
|
|
||||||
R.drawable.sample_6, R.drawable.sample_7,
|
|
||||||
R.drawable.sample_0, R.drawable.sample_1,
|
|
||||||
R.drawable.sample_2, R.drawable.sample_3,
|
|
||||||
R.drawable.sample_4, R.drawable.sample_5,
|
|
||||||
R.drawable.sample_6, R.drawable.sample_7,
|
|
||||||
R.drawable.sample_0, R.drawable.sample_1,
|
|
||||||
R.drawable.sample_2, R.drawable.sample_3,
|
|
||||||
R.drawable.sample_4, R.drawable.sample_5,
|
|
||||||
R.drawable.sample_6, R.drawable.sample_7
|
|
||||||
};
|
|
||||||
}
|
|
@ -5,20 +5,33 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.GridView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
|
|
||||||
public class MarksFragment extends Fragment {
|
public class MarksFragment extends Fragment {
|
||||||
|
|
||||||
Activity mActivity;
|
Activity mActivity;
|
||||||
|
|
||||||
|
final String lista[] = {
|
||||||
|
"Donut",
|
||||||
|
"Eclair",
|
||||||
|
"Froyo",
|
||||||
|
"Gingerbread",
|
||||||
|
"Honeycomb",
|
||||||
|
"Ice Cream Sandwich",
|
||||||
|
"Jelly Bean",
|
||||||
|
"KitKat",
|
||||||
|
"Lollipop",
|
||||||
|
"Marshmallow"
|
||||||
|
};
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@ -36,15 +49,15 @@ public class MarksFragment extends Fragment {
|
|||||||
|
|
||||||
View view = inflater.inflate(R.layout.fragment_marks, container, false);
|
View view = inflater.inflate(R.layout.fragment_marks, container, false);
|
||||||
|
|
||||||
GridView gridview = (GridView) view.findViewById(R.id.gridview);
|
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
||||||
gridview.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity()
|
recyclerView.setHasFixedSize(true);
|
||||||
|
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2);
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
ArrayList<String> array = new ArrayList<>(Arrays.asList(lista));
|
||||||
|
ImageAdapter adapter = new ImageAdapter(view.getContext(),array);
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
gridview.setOnItemClickListener(new OnItemClickListener() {
|
|
||||||
public void onItemClick(AdapterView<?> parent, View v,
|
|
||||||
int position, long id) {
|
|
||||||
Toast.makeText(mActivity,"HALLO", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 58 KiB |
BIN
app/src/main/res/drawable/sample_0.png
Normal file
BIN
app/src/main/res/drawable/sample_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
@ -1,18 +1,14 @@
|
|||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="io.github.wulkanowy.activity.dashboard.marks.MarksFragment">
|
android:fitsSystemWindows="true"
|
||||||
|
tools:context="io.github.wulkanowy.activity.dashboard.marks.MarksFragment">
|
||||||
|
|
||||||
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/gridview"
|
android:id="@+id/card_recycler_view"
|
||||||
|
android:scrollbars="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:columnWidth="90dp"
|
|
||||||
android:numColumns="auto_fit"
|
|
||||||
android:verticalSpacing="10dp"
|
|
||||||
android:horizontalSpacing="10dp"
|
|
||||||
android:gravity="center"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
20
app/src/main/res/layout/row_layout.xml
Normal file
20
app/src/main/res/layout/row_layout.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@color/colorPrimaryDark"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/img_android"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_android"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user