mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 11:56:09 -06:00
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:support-vector-drawable: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'
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.DeviceDefault">
|
||||
android:theme="@style/Theme.AppCompat">
|
||||
<activity
|
||||
android:name=".activity.started.StartedActivity"
|
||||
android:noHistory="true"
|
||||
|
@ -1,62 +1,56 @@
|
||||
package io.github.wulkanowy.activity.dashboard.marks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
|
||||
public class ImageAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ViewHolder> {
|
||||
|
||||
public ImageAdapter(Context c) {
|
||||
this.mContext = c;
|
||||
private Context context;
|
||||
private ArrayList<String> lista;
|
||||
|
||||
public ImageAdapter(Context context, ArrayList<String> lista) {
|
||||
this.lista = lista;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mThumbIds.length;
|
||||
@Override
|
||||
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) {
|
||||
return null;
|
||||
@Override
|
||||
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) {
|
||||
return 0;
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return lista.size();
|
||||
}
|
||||
|
||||
// create a new ImageView for each item referenced by the Adapter
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ImageView imageView;
|
||||
if (convertView == null) {
|
||||
// if it's not recycled, initialize some attributes
|
||||
imageView = new ImageView(mContext);
|
||||
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
|
||||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
imageView.setPadding(8, 8, 8, 8);
|
||||
} else {
|
||||
imageView = (ImageView) convertView;
|
||||
public class ViewHolder extends RecyclerView.ViewHolder{
|
||||
private TextView tv_android;
|
||||
private ImageView img_android;
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
|
||||
tv_android = (TextView)view.findViewById(R.id.tv_android);
|
||||
img_android = (ImageView) view.findViewById(R.id.img_android);
|
||||
}
|
||||
|
||||
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.os.Bundle;
|
||||
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.View;
|
||||
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;
|
||||
|
||||
public class MarksFragment extends Fragment {
|
||||
|
||||
Activity mActivity;
|
||||
|
||||
final String lista[] = {
|
||||
"Donut",
|
||||
"Eclair",
|
||||
"Froyo",
|
||||
"Gingerbread",
|
||||
"Honeycomb",
|
||||
"Ice Cream Sandwich",
|
||||
"Jelly Bean",
|
||||
"KitKat",
|
||||
"Lollipop",
|
||||
"Marshmallow"
|
||||
};
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@ -36,15 +49,15 @@ public class MarksFragment extends Fragment {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_marks, container, false);
|
||||
|
||||
GridView gridview = (GridView) view.findViewById(R.id.gridview);
|
||||
gridview.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity()
|
||||
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
||||
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;
|
||||
}
|
||||
|
||||
|
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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="io.github.wulkanowy.activity.dashboard.marks.MarksFragment">
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="io.github.wulkanowy.activity.dashboard.marks.MarksFragment">
|
||||
|
||||
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/gridview"
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/card_recycler_view"
|
||||
android:scrollbars="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:columnWidth="90dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:verticalSpacing="10dp"
|
||||
android:horizontalSpacing="10dp"
|
||||
android:gravity="center"
|
||||
/>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</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…
Reference in New Issue
Block a user