Last active
February 26, 2016 22:35
-
-
Save tsuginodan/602437a3b64060d7a59a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class About { | |
private String titulo; | |
private String subtitulo; | |
public About(String titulo, String subtitulo) { | |
this.titulo = titulo; | |
this.subtitulo = subtitulo; | |
} | |
public String getTitulo() { | |
return titulo; | |
} | |
public void setTitulo(String titulo) { | |
this.titulo = titulo; | |
} | |
public String getSubtitulo() { | |
return subtitulo; | |
} | |
public void setSubtitulo(String subtitulo) { | |
this.subtitulo = subtitulo; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*imports here*/ | |
public class ActivityTaskList extends AppCompactActivity { | |
@InjectView(R.id.index_list) | |
RecyclerView indexList; | |
private ArrayList<About> list; | |
FinalAdapter finalAdapter; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.content_index); | |
ButterKnife.inject(this); | |
list = new ArrayList<>(); | |
for (int i = 0; i < 50; i++) { | |
/*simple class task*/ | |
list.add(new About("Task " + i, "Task X")); | |
} | |
finalAdapter = new FinalAdapter(list); | |
//tiene datos fijos | |
indexList.setHasFixedSize(true); | |
indexList.setAdapter(finalAdapter); | |
indexList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); | |
//indexList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); | |
indexList.setItemAnimator(new DefaultItemAnimator()); | |
} | |
public void nuevoItem(View v) { | |
list.add(new About("Task x", "Task X")); | |
finalAdapter.notifyItemChanged(1); | |
//util.snackbarShort(v, "Mensaje de Prueba"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<LinearLayout android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> | |
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:onClick="nuevoItem" android:text="AGREGAR"/> | |
<android.support.v7.widget.RecyclerView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/index_list"/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FinalAdapter extends RecyclerView.Adapter<FinalAdapter.TaskViewHolder> { | |
private ArrayList<About> listado; | |
public FinalAdapter(ArrayList<About> listado) { | |
this.listado = listado; | |
} | |
@Override | |
public TaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
/*layout = linearlayout wrapping a textview*/ | |
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_single_line, parent, false); | |
TaskViewHolder vh = new TaskViewHolder(v); | |
return vh; | |
} | |
@Override | |
public void onBindViewHolder(TaskViewHolder holder, int position) { | |
About t = listado.get(position); | |
holder.txtListitem.setText(t.getTitulo()); | |
} | |
@Override | |
public int getItemCount() { | |
return listado.size(); | |
} | |
static class TaskViewHolder extends RecyclerView.ViewHolder { | |
@InjectView(R.id.txt_listitem) | |
TextView txtListitem; | |
public TaskViewHolder(View itemView) { | |
super(itemView); | |
ButterKnife.inject(this,itemView); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> | |
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/txt_listitem"/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment