Sziasztok,
egy ListActivity ős view-m van:
public abstract class ActivityList extends ListActivity {
protected ListView listView;
public abstract void renderListView( String filter );
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.commonlist );
listView = getListView();
}
}
Ez az ActivitiList őse lesz több hasonló képernyőnek, a renderlistview()-et ők maguknak valósítják meg, SimpleCursorAdapter-rel pl.:
public class ActivityProductList extends ActivityList {
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
renderListView( null );
}
@Override
public void renderListView( String filter ) {
...
SimpleCursorAdapter sca = new SimpleCursorAdapter( this, listItemId, mCursor, from, to );
setListAdapter( sca );
}
A listview szépen működik.
A felhasználó teszi amit akar, aztán megnyomja a KÉSZ gombot. Ez a gomb az ős activity-ben van, amiben a listview is. Az eventhandlere:
protected void getCheckedItems() {
SimpleCursorAdapter adapter = (SimpleCursorAdapter)this.getListAdapter(); // <<<<
Cursor cursor = adapter.getCursor();
...
}
A probléma az, hogy kommenttel jelölt sorban elszáll a program ismeretlen exceptionnel és nem tom miért?????
Van valakinek valami 5lete?
Előre is köszönöm!
Page
viewed times
#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))
7 Comments
Auth Gábor
Logba mit ír?
Franz Max
Android 2.1, SE XPERIA 8
A logban sajnos nem látok semmi erre utalót (log collector), debuggolom a programot. A stackoverflow-ra írtam egy bővebb körülírását a problémának, azt ideteszem:
Since I need a checked list I use
CheckedTextView
in listitem template. The user can check as many items in list as he want. It's working fine.I have a
ListActivity
root view:It is abstract, because
ActivitiList
will be the parent for other view classes, like products, clients, etc. The abstract renderlistview() will be implemented by children withSimpleCursorAdapter
, eg.:The ActivityProductList is working fine. The user does it all he want, then clicks on the FINISH button defined and implemented in parent class, where the listview is, too. His event handler is as follows:
The concept is: get the selected item's ids.
However, in the line what I marked by comment the program crashes with error:
The this.getListAdapter() gives me a
CursorAdapter
than the cast will crashes.My conception is: ActivityList (this) has getListAdapter() method which gives Listadapter. Because the ListActivity's listadapter was set by SimpleCursorAdapter, I use typecasting on it to SimpleCursorAdapter. After that the adapter has getCursor() method which gives the necessary cursor. Maybe it's wrong conception?
Az érdekesség az (legalábbis számomra ) hogy a
Jó mondjuk továbbra is lelkes kezdő vagyok...
Volna valami ötleted?
Auth Gábor
Itt a log, írja is benne, hogy ClassCastException... valószínűleg mégsem SimpleCursorAdapter az adott példány, írasd ki valahova, hogy mi a pontos típusa:
Akkor kiderül, hogy mit kapsz, mert lehet, hogy nem SimpleCursorAdapter (ami egy leszármazott osztály), hanem annak egy őse, vagy más ágon leszármazottja, és meg kell keresni a közös őst, például CursorAdapter esélyes lehet.
Franz Max
a kód:
ez kerül logba a kód kiegészítésével:
Auth Gábor
Hmm... ez fura. Egyelőre nincs ötletem, de még este megnézem.
Franz Max
Szia,
sikerült ránézned? Teljesen nem értem, áll a dolog... A kurzorra sajna szükségem van, mert a lista lehet korábban szűrt sql eredménye is, amit a kurzor visszaadna. Így a
miatt kell ez a dudva hibás sor...
Köszi
Auth Gábor
Sajnos nincs ötletem. Mennie kellene ránézésre, nem tudom miért nem működik.