2014-11-24 2 views
0

мне нужно, чтобы показать пользовательские элементы в списке, но после попытки много различных способов решить эту проблему, я до сих пор застрял с этой ошибкой:Заливка ListView из массива объектов

> java.lang.RuntimeException: Unable to start activity 
> ComponentInfo{quinto3.et37.agendadeviajes/quinto3.et37.agendadeviajes.Principal}: 
> java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams 
> cannot be cast to android.widget.AbsListView$LayoutParams 

Вот основная деятельность

public class Principal extends Activity { 

    private static final int ACTIVITY_CREATE = 0; 
    private static final int ACTIVITY_EDIT = 1; 

    private ArrayAdapter<TipoDeViaje> mAdapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.agenda_principal); 
     ListView lista = (ListView) findViewById(R.id.lista); 
     View footer = ((LayoutInflater)  this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_add_button,  (ViewGroup) getWindow().getDecorView().getRootView(), false); 
     lista.addFooterView(footer, null, false); 
     llenarLista(); 
     registerForContextMenu(lista); 
    } 

    private void llenarLista() { 
     ListView lista = (ListView) findViewById(R.id.lista); 
     TipoDeViajeDAO tManager = new TipoDeViajeDAO(this); 
     ArrayList<TipoDeViaje> tipoList = tManager.traerTodos(this); 
     mAdapter = new AdapterTipoDeViaje(this,tipoList); 
     lista.setAdapter(mAdapter); 
    } 

    public void footerClick(View v) { 
     Toast.makeText(this, "pls", Toast.LENGTH_SHORT).show(); 
     Intent i = new Intent(this, EditTipoDeViaje.class); 
     startActivityForResult(i, ACTIVITY_CREATE); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     super.onActivityResult(requestCode, resultCode, intent); 
     llenarLista(); 
    } 

Вот мой заказ адаптер

public class AdapterTipoDeViaje extends ArrayAdapter<TipoDeViaje> { 
    public AdapterTipoDeViaje(Context context, ArrayList<TipoDeViaje> tipos) { 
     super(context, 0, tipos); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // Get the data item for this position 
     TipoDeViaje t = getItem(position); 
     // Check if an existing view is being reused, otherwise inflate the view 
     if (convertView == null) { 
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.lista_fila, parent,  false); 
     } 
     // Lookup view for data population 
     TextView desdeText = (TextView) convertView.findViewById(R.id.desde_text); 
     TextView hastaText = (TextView) convertView.findViewById(R.id.hasta_text); 
     // Populate the data into the template view using the data object 
     desdeText.setText(t.getDesde().getNombre()); 
     hastaText.setText(t.getHasta().getNombre()); 
     // Return the completed view to render on screen 
     return convertView; 
    } 

А вот мой lista_fila.xml (макет я тусклый т использовать для строки)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/desde_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="desde" 
     android:textSize="30sp" /> 

    <TextView 
     android:id="@+id/hasta_text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="hasta" 
     android:textSize="30sp" /> 

    <ImageButton 
     android:id="@+id/boton_agregar_registro" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/boton_agregar_registro" 
     android:src="@drawable/ic_add_viaje" /> 

</LinearLayout> 

Вот agenda_principal

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ListView 
     android:id="@+id/lista" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

А вот footer_add_button

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/footer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:paddingTop="7dip" > 
    <ImageButton 
     android:id="@+id/footer_1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dip" 
     android:gravity="center" 
     android:onClick="footerClick" 
     android:src="@drawable/ic_add_button" 
     android:contentDescription="@string/desc_footer_button"/> 
</LinearLayout> 

ответ

1

Проблема заключается в инфляции сноска.

Попробуйте это:

View footer = LayoutInflater.from(this).inflate(R.layout.footer_add_button, lista, false); 
lista.addFooterView(footer); 
+0

я получаю ошибку Thsi сейчас: метод Inflate (интермедиат, ViewGroup, булево) в типе LayoutInflater не применяется для аргументов (INT, ListView, нуль) – AndroidPug

+0

Он работает с ложным, а не с нулевым, спасибо большое – AndroidPug

+0

Oups извините за ошибку;) хорошо знать, что вы нашли решение. – pdegand59

Смежные вопросы