I need to show custom items on a list but after trying many different ways to solve the problem I'm still stuck with this error:
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
Here is the principal activity
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();
}
Here is my custom adapter
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;
}
And here is my lista_fila.xml (the layout I want to use for the row)
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
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>
No comments:
Post a Comment