android


Android: Add LinearLayout first at ListView


I want add new item to top at listview
After run, application force closed
Code :
final ArrayList<StructNote> notesPage = new ArrayList<StructNote>();
final ListView lstContent = (ListView) findViewById(R.id.lstContent);
adapter = new AdapterNote(notesPage);
View addNew = G.inflater.inflate(R.layout.addnew, null);
adapter.insert(addNew, 0);
lstContent.setAdapter(adapter);
adapter.notifyDataSetChanged();
Error log :
04-01 15:39:02.163: E/AndroidRuntime(1908): java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to com.app.network.StructNote
04-01 15:39:02.163: E/AndroidRuntime(1908): at com.app.network.AdapterNote.getView(AdapterNote.java:612)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.AbsListView.obtainView(AbsListView.java:2033)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.makeAndAddView(ListView.java:1772)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.fillDown(ListView.java:672)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.fillFromTop(ListView.java:732)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.ListView.layoutChildren(ListView.java:1611)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.view.View.layout(View.java:11278)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.view.ViewGroup.layout(ViewGroup.java:4224)
04-01 15:39:02.163: E/AndroidRuntime(1908): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
StructNote save item each listview
StructNote :
public class StructNote {
public int id;
public String singer;
public String title;
}
AdapterNote set into listview foreach child of listview
AdapterNote :
public class AdapterNote extends ArrayAdapter<StructNote> {
public AdapterNote(ArrayList<StructNote> array) {
super(G.context, R.layout.post, array);
}
private static class ViewHolder {
...
}
Try this:
final ArrayList<StructNote> notesPage = new ArrayList<StructNote>();
final ListView lstContent = (ListView) findViewById(R.id.lstContent);
adapter = new AdapterNote(notesPage);
LayoutInflater inflater = getLayoutInflater();
View addNew = inflater.inflate(R.layout.addnew, lstContent, false);
lstContent.addHeaderView(addNew, null, false);
lstContent.setAdapter(adapter);
adapter.notifyDataSetChanged();

Related Links

Updating a TextView in an Activity from a Service in Android?
Android adding a submenu to a menuItem, where is addSubMenu()?
“OAuthException - An unknown error has occurred” when commenting articles through the Graph API
Linearlayout for different screen sizes
Running Cygwin commands from batch file
Android Searchview with background hint
Making an android map menu to change map type
rails Devise http authenticating mobile
Check if RunOnUiThread is necessary?
How can I debug an Android app without Eclipse?
Popup doesn't become unvisible but it pass through code and nothing happens
How to refresh asyncTask from another acctivity?
Layout problem with listView
Get facebook email after login in Android
Customize Wikitude main view with Wikitude API
how to open activity in diffrent tab from one tab?

Categories

HOME
3d
numbers
toolbox
oracle-apex-5
requirements
ms-access-2016
cublas
limit
regular-language
jetty
pearson-correlation
vsm
iis-6
odoo-8
discrete-mathematics
fosrestbundle
redis-sentinel
google-form
selenium-ide
cumulocity
docx
symbol
google-data-studio
foreign-keys
identity-management
topology
dataflow-diagram
strongname
dapper-extensions
slidetoggle
syntax-highlighting
stackexchange
jasmine-node
8051
angular-translate
winexe
alm
calculation
livelink
paragraph
turfjs
login-script
instantiation
installshield-le
baidu-map
batching
docfx
loading
diacritics
unordered-map
apollostack
tcc
snapchat
textsum
twilio-click-to-call
qtranslate
boxing
arules
lsyncd
rxtx
sandcastle
restore
usart
cubism.js
meteor-packages
winusb
signalr.client
drawstring
lean
shopping
php-socket
query-by-example
uiactionsheet
libvlc
assertion
rewrite
sql-server-data-tools
google-refine
jquery-forms-plugin
xmltype
exceldatareader
nodelist
ghcjs
jjaql
memset
android-framework
android-audiorecord
mysql-error-1044
code-duplication
unit-of-work
nebula
epiceditor
jquery-1.9
asplinkbutton
bjyauthorize
robotlegs
pdfviewer
vfs
web-farm
rmiregistry
gobject-introspection
mbeans
event-receiver
svk
facebook-iframe
django-piston
wcf-instancing
windows-identity
product-management
commercial-application

Resources

Encrypt Message