¿Es posible ajustar el adaptador al diseño lineal?
¿Es posible ajustar el adaptador a un LinearLayout
?
No quiero usar ListView
ya que estoy usando ScrollView
. Así que estoy usando LinearLayout
…
- Cómo agregar scrollview a keyboardView en android
- Android WebView dentro de ScrollView solo desplaza scrollview
- ImageView: recicla automáticamente el mapa de bits si ImageView no está visible (dentro de ScrollView)
- Espacios en blanco usando la vista web de android dentro de scrollview con una red móvil de jQuery
- Android - ScrollView como foursquare con mapas + lista
En eso estoy añadiendo dinámicamente las vistas y ahora necesito utilizar el adaptador … así que cualquier persona tiene cualquier sugerencia?
Yo estoy haciendo esto
LinearLayout clientList = (LinearLayout) findViewById(R.id.clients); adapter = new Sample1AdapterActivity(this, arrayList); View list = (ListView) getLayoutInflater().inflate(R.layout.user_details, getListView(), false);
- Relativelayout dentro Scrollview no funciona
- Restablecer desplazamiento en ScrollView
- Android :: VideoView dentro de un ScrollView
- ¿Cómo puedo hacer que mi cuadro de diálogo de Android sea de pantalla completa?
- Sincronizar la posición de desplazamiento de ScrollView en todos los fragmentos dentro de ViewPager
- Barras de desplazamiento de estilo de tableta Gmail con barra de acción transparente
- Cómo hacer un Scroll Listener para WebView en Android
- NestedScrollView (NSV) en CoordinatorLayout (CL): NSV no en la parte superior cuando se carga
No, no puedes Lo que puede hacer es inflar la fila única y añadirla a LinearLayout. En pseudo código:
LinearLayout linearLayout = (LinearLayout) findViewById(...); LayoutInflater inflater = LayoutInflater.from(this); for (item in arrayList) { View view = inflater.inflate(R.layout.row, linearLayout, false); // set item content in view linearLayout.addView(view) }
Sí, puedes agregar tu propia implementación LinearLayout específica para obtener vistas secundarias desde el adaptador. Sin embargo, mi implementación básica no proporcionará todo el código de recopilación de vista proporcionado por la vista de lista.
/** * A linear layout that will contain views taken from an adapter. It differs * from the list view in the fact that it will not optimize anything and * draw all the views from the adapter. It also does not provide scrolling. * However, when you need a layout that will render views horizontally and * you know there are not many child views, this is a good option. * * @author Vincent Mimoun-Prat @ MarvinLabs */ public class AdapterLinearLayout extends LinearLayout { private Adapter adapter; private DataSetObserver dataSetObserver = new DataSetObserver() { @Override public void onChanged() { super.onChanged(); reloadChildViews(); } }; @TargetApi(Build.VERSION_CODES.HONEYCOMB) public AdapterLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setOrientation(LinearLayout.HORIZONTAL); } public AdapterLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); setOrientation(LinearLayout.HORIZONTAL); } public AdapterLinearLayout(Context context) { super(context); setOrientation(LinearLayout.HORIZONTAL); } public void setAdapter(Adapter adapter) { if (this.adapter == adapter) return; this.adapter = adapter; if (adapter != null) adapter.registerDataSetObserver(dataSetObserver); reloadChildViews(); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (adapter != null) adapter.unregisterDataSetObserver(dataSetObserver); } private void reloadChildViews() { removeAllViews(); if (adapter == null) return; int count = adapter.getCount(); for (int position = 0; position < count; ++position) { View v = adapter.getView(position, null, this); if (v != null) addView(v); } requestLayout(); } }