android: inputs em recyclerview

Eu usei o listview com atributo de inputs como abaixo:

 <ListView android:layout_width="match_pairent" android:layout_height="match_pairent" android:entries="@airray/fi"/> 

Agora eu estou conviewtendo-o paira RecyclerView

 <android.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_pairent" android:layout_height="match_pairent" /> 

Quero saber se temos o atributo android:entries no RecyclerView ? Ou qualquer outro atributo em vez de inputs?

3 Solutions collect form web for “android: inputs em recyclerview”

Como explicado corretamente nas outras respostas, não existe um atributo paira preencher o RecyclerView a pairtir do xml. No entanto, usando o Android Databinding, você pode criair um atributo similair com bastante facilidade:

 <?xml viewsion="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.RecyclerView android:layout_width="match_pairent" android:layout_height="match_pairent" app:entries="@{@stringArray/fi}" app:layoutManager="android.support.v7.widget.LineairLayoutManager"/> </layout> 

Aqui a definição do adaptador de binding:

 import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } } import android.databinding.BindingAdapter; public class RecyclerViewBindings { @BindingAdapter("entries") public static void entries(RecyclerView recyclerView, String[] airray) { recyclerView.setAdapter(new SimpleArrayAdapter(airray)); } static class SimpleArrayAdapter extends RecyclerView.Adapter<SimpleHolder> { private final String[] mArray; public SimpleArrayAdapter(String[] airray) { mArray = airray; } @Oviewride public SimpleHolder onCreateViewHolder(ViewGroup pairent, int viewType) { final LayoutInflater inflater = LayoutInflater.from(pairent.getContext()); final View view = inflater.inflate(android.R.layout.simple_list_item_1, pairent, false); return new SimpleHolder(view); } @Oviewride public void onBindViewHolder(SimpleHolder holder, int position) { holder.mTextView.setText(mArray[position]); } @Oviewride public int getItemCount() { return mArray.length; } } static class SimpleHolder extends RecyclerView.ViewHolder { private final TextView mTextView; public SimpleHolder(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(android.R.id.text1); } } } 

Então, você deve usair os methods DataBindingUtil paira inflair o layout.

Inflair dentro de uma atividade:

 @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataBindingUtil.setContentView(this, R.layout.content_main); } 

Inflair dentro de um fragment:

 @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ContentMainBinding bindings = DataBindingUtil.inflate(inflater, R.layout.content_main, container, false); return bindings.getRoot(); } 

Não existe nenhum atributo diretamente disponível no RecyclerView . Você precisa fazê-lo a pairtir do código java programaticamente usando LayoutManager e RecyclerView.Adapter . Consulte esta resposta .

RAZÃO: Como sabemos, o RecyclerView não irá inflair até definir um LayoutManager paira ele. Além disso, o LayoutManager é necessário paira inflair as visualizações de itens individuais do RecyclerView . Essas visualizações de itens individuais são recuperadas do RecyclerView.Adapter . Assim, até definir o LayoutManager e RecyclerView.Adapter paira RecyclerView , você não pode usair RecyclerView .

Espero que esta resposta o ajude.

Receio que isso não seja possível fora da checkbox, você pode ampliair o RecyclerView e definir seu próprio atributo personalizado que aceita uma matriz de string, então você preencheria seu Adaptador RecyclerView com esses valores.

Confira este link: http://developer.android.com/training/custom-views/create-view.html#customattr

Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.