java - Android ListView with ArrayAdapter doesn't show anything -
java - Android ListView with ArrayAdapter doesn't show anything -
i know there lot of posts on how create android listview, after looking through of them can't figure out problem is. i'm new android , bit overwhelmed. activity runs without showing content.
this activity:
package com.example.myfirstapp; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.widget.listview; public class historyactivity extends activity { customrowadapter customrowadapter; listview listview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_history); listview = (listview)findviewbyid(r.id.listview); customrowadapter = new customrowadapter(getapplicationcontext()); listview.setadapter(customrowadapter); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.history, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } }
this activity_history.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="16dp" android:paddingright="16dp" android:orientation="vertical"> <listview android:id="@+id/listview" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout>
the xml input in listview (custom_row.xml):
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="16dp" android:paddingright="16dp" android:orientation="vertical"> <textview android:id="@+id/textview1" android:background="@drawable/box" android:textsize="18sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/app_name" /> <textview android:id="@+id/textview2" android:background="@drawable/box" android:textsize="18sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/app_name" /> <textview android:id="@+id/textview3" android:background="@drawable/box" android:textsize="18sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/app_name" /> </linearlayout>
and customrowadapter.java:
package com.example.myfirstapp; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.textview; public class customrowadapter extends arrayadapter<string> { private string[] text1 = { "google plus", "twitter", "facebook", "instagram"}; private string[] text2 = { "test1", "test2", "test3", "test4"}; private string[] text3 = { "google plus", "twitter", "facebook", "instagram"}; private layoutinflater layoutinflater; private context context; public customrowadapter(context context) { super(context,0); layoutinflater= (layoutinflater)context.getsystemservice(context.layout_inflater_service); this.context=context; } @override public view getview(int position, view view, viewgroup viewgroup){ view = layoutinflater.inflate(r.layout.custom_row,null); textview textviewt1 = (textview)view.findviewbyid(r.id.textview1); textview textviewt2 = (textview)view.findviewbyid(r.id.textview2); textview textviewt3 = (textview)view.findviewbyid(r.id.textview3); // textviewt1.settext("test"); // textviewt2.settext(text2[0]); // textviewt3.settext(text3[0]); homecoming view; } @override public int getcount(){ homecoming 0; } }
hope can help me out.
your listview not showing nil because of
@override public int getcount(){ homecoming 0; }
getcount
has homecoming number of elements belong dataset. instance
@override public int getcount(){ homecoming text1.length; }
java android listview
Comments
Post a Comment