El método getView () de ArrayAdapter no se recibe

Soy muy nuevo en el desarrollo de Android. Estoy tratando de construir una aplicación con etiquetas (que se agregan a través de fragmentos). En uno de los fragmentos, estoy tratando de mostrar una lista. Esta lista se ha poblado usando ListAdapter que he extendido desde ArrayAdapter y he sobrecargado el método getView (). Este es mi fragmento

public class tabcontentActivity extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { return null; } View v = (LinearLayout) inflater.inflate(R.layout.tablayout, container, false); ListView lv = (ListView) v.findViewById(R.id.listview1); ListViewAdapter adapter = new ListViewAdapter(container.getContext(), android.R.layout.simple_list_item_1, R.id.textview1); adapter.notifyDataSetChanged(); lv.setAdapter(adapter); return v; } } 

Y así es como he implementado el ListAdapter

 public class ListViewAdapter extends ArrayAdapter { Context context1; public ListViewAdapter(Context context,int resource, int textViewResourceId) { super(context,resource,textViewResourceId); this.context1 = context; System.out.println("here aswell!!!!!!"); // TODO Auto-generated constructor stub } public View getView(int arg0, View convertView, ViewGroup arg2) { // TODO Auto-generated method stub System.out.println("@@@I AM HERE@@@"); LayoutInflater inflater = LayoutInflater.from(context1); convertView = inflater.inflate(R.layout.tablayout, null); TextView wv = (TextView) convertView.findViewById(R.id.textview1); String summary = "<html><body><h1>This is happening!!!</h1></body></html>"; wv.setText(Html.fromHtml(summary)); convertView.setTag(wv); return convertView; } } 

El diseño xml es

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="fill_parent" > </ListView> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="myreader" /> </LinearLayout> 

Por favor, ayúdame a encontrar un camino por el cual pueda hacer que esto funcione.

Se le olvidó proporcionar los datos al constructor y luego hacer la llamada correcta dentro del constructor:

 public ListViewAdapter(Context context,int resource, int textViewResourceId, List<YourObjectType> items) { super(context,resource,textViewResourceId, items); this.context1 = context; // TODO Auto-generated constructor stub } 

No le está suministrando ningún dato actual. Si todavía desea ver lo que está sucediendo en la lista, anule la función getCount ().

Creo que es algo así.

 public int getCount(){ return 1; } 

Esto dibujará un elemento en su lista. Y también llamar a su getView (). Y ya una vez que descubra cómo suministrar su fuente de datos, cambie el getCount () al tamaño de su lista. Echa un vistazo a un tutorial aquí

http://www.shubhayu.com/android/listview-with-arrayadapter-and-customized-items

Parece que no ha especificado una fuente de datos para su adaptador. Una fuente de datos es cualquier cosa que proporciona datos que se muestran, por ejemplo un arraylist o un cursor. Si no hay datos de un origen de datos, getview () no será llamado en absoluto.

Cuando estamos creando un arrayadadter personalizado debemos usar

 public ArrayAdapter (Context context, int textViewResourceId, T[] objects) public ArrayAdapter (Context context, int resource, int textViewResourceId, T[] objects) public ArrayAdapter (Context context, int textViewResourceId, List<T> objects) public ArrayAdapter (Context context, int resource, int textViewResourceId, List<T> objects) 

Si no estamos usando el adaptador mencionado arriba, necesitamos anular el método getCount ().

  adapter.notifyDataSetChanged(); lv.setAdapter(adapter); 

Intercambiar las posiciones

 Layoutinflator=getLayoutInflator(); 
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { View v = (LinearLayout) inflater.inflate(R.layout.tablayout, container, false); ListView lv = (ListView) v.findViewById(R.id.listview1); ListViewAdapter adapter = new ListViewAdapter(container.getContext(), android.R.layout.simple_list_item_1, R.id.textview1); adapter.notifyDataSetChanged(); lv.setAdapter(adapter); } else{ View v = (LinearLayout) inflater.inflate(R.layout.tablayout, container, false); ListView lv = (ListView) v.findViewById(R.id.listview1); ListViewAdapter adapter = new ListViewAdapter(container.getContext(), android.R.layout.simple_list_item_1, R.id.textview1); adapter.notifyDataSetChanged(); lv.setAdapter(adapter); } return v; } 

Y sobreescribir el método getcount

  public int getCount(){ return 100; } 
  • Disposición del teclado que oculta la barra de acción del androide?
  • ¿Por qué onLayout y onSizeChanged se llaman dos veces en un cambio de orientación?
  • Escala widget en Android (dp, px, tamaño de pantalla)
  • Android - Cómo comprobar si textview es nulo o no nulo
  • Android: Algo mejor que android: ellipsize = "end" para agregar "..." a cadenas largas truncadas?
  • Cómo transferir datos extra de un fragmento a otro a través de la actividad
  • ¿Cómo hacer que el trasfondo de una actividad sea translúcido?
  • Cómo hacer que customAdapter rellene la altura de gridview
  • Cómo editar el menú de la barra de Acción de Fragmento
  • Android: Cómo deshacerse de la frontera extraña alrededor del diálogo de progreso
  • ¿Por qué mi diseño se ensucia después de borrar el flag FLAG_TRANSLUCENT_STATUS?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.