Skip to content

Instantly share code, notes, and snippets.

@BaptisteDixneuf
Last active April 28, 2017 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaptisteDixneuf/ffa35112f9859f656918855af5129601 to your computer and use it in GitHub Desktop.
Save BaptisteDixneuf/ffa35112f9859f656918855af5129601 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:padding="10dp"
>
<TextView
android:id="@+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_marginLeft="10dp"
android:textStyle="bold"
tools:text="Nom"
/>
</RelativeLayout>
package eni.baptistedixneuf.fr.sudoku.bo;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Created by bdixneuf2015 on 28/04/2017.
*/
public class Level implements Parcelable {
private int id;
private String nom;
public Level(){}
protected Level(Parcel in){
id = in.readInt();
nom = in.readString();
}
public static final Parcelable.Creator<Level> CREATOR = new Parcelable.Creator<Level>(){
@Override
public Level createFromParcel(Parcel source) {
return new Level(source);
}
@Override
public Level[] newArray(int size) {
return new Level[size];
}
};
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(nom);
}
public int describeContents() {
return 0;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
}
package eni.baptistedixneuf.fr.sudoku.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
import eni.baptistedixneuf.fr.sudoku.R;
import eni.baptistedixneuf.fr.sudoku.bo.Level;
/**
* Created by bdixneuf2015 on 28/04/2017.
*/
public class LevelAdapter extends ArrayAdapter<Level> {
//tweets est la liste des models à afficher
public LevelAdapter(Context context, List<Level> levels) {
super(context, 0, levels);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.level_list,parent, false);
}
LevelViewHolder viewHolder = (LevelViewHolder) convertView.getTag();
if(viewHolder == null){
viewHolder = new LevelViewHolder();
viewHolder.nom = (TextView) convertView.findViewById(R.id.nom);
convertView.setTag(viewHolder);
}
//getItem(position) va récupérer l'item [position] de la List<Tweet> tweets
Level level = getItem(position);
//il ne reste plus qu'à remplir notre vue
viewHolder.nom.setText(level.getNom());
return convertView;
}
private class LevelViewHolder {
public TextView nom;
}
}
//On rafraichit la liste
LevelAdapter adapter = new LevelAdapter(MainActivity.this, levels);
mListView = (ListView) findViewById(R.id.listView);
mListView.setAdapter(adapter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment