Android Listview Hides Titlebar -
i'm trying make app - has 3 activities. first 2 listviews in linear layouts, , each of them prevents title bar showing up. title bar mean section @ top of activity displays activity's name option setting. third activity not listview, , displays title bar normally, leads me think may problem listviews.
the xml first page is:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".selectclass"> <listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent"> </listview>
my java class doesn't display, although set array adapter , onclick listener. if necessary understand what's going on let me know , i'll post them. appreciate or clues. thank you!
edit: first page's java:
package com.example.graeme.dnd5echaracterroller; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.linearlayout; import android.view.view; import android.widget.textview; public class selectclass extends listactivity { private static string classstring; public static void setclassstring(string classstring) { selectclass.classstring = classstring; } public static string getclassstring() { return classstring; } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_select_class); //initialize available class choices final string[] classes = {"barbarian","bard","cleric","druid", "fighter","monk","paladin","ranger","rogue","sorcerer", "warlock", "wizard"}; arrayadapter<string> classadapter = new arrayadapter<>(getlistview().getcontext(), r.layout.classlayout, r.id.classname, classes); getlistview().setadapter(classadapter); //set on click listener selected class item adapterview.onitemclicklistener itemclickedhandler = new adapterview.onitemclicklistener(){ public void onitemclick(adapterview<?> parent, view v, int position, long id){ //start new intent headed selectroll, fill class string selected intent sendclassintent = new intent(selectclass.this, selectroll.class); //each list item has image, , text //first grab list item, grab text linearlayout ll = (linearlayout)v; textview tv = (textview)(ll).findviewbyid(r.id.classname); setclassstring((string)(tv.gettext())); startactivity(sendclassintent); } }; getlistview().setonitemclicklistener(itemclickedhandler); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_select_class, menu); return 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(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
you should modify first activity structure
public class selectclass extends appcompatactivity { ... private listview mlistview; ... @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_select_class); // initialize lisview mlistview = (listview) findviewbyid(r.id.lisview_id); // lisview id //initialize available class choices final string[] classes = {"barbarian","bard","cleric","druid", "fighter","monk","paladin","ranger","rogue","sorcerer", "warlock", "wizard"}; arrayadapter<string> classadapter = new arrayadapter<> (this, r.layout.classlayout, r.id.classname, classes); // update mlistview.setadapter(classadapter); ... } @override public boolean oncreateoptionsmenu(menu menu) { .... } @override public boolean onoptionsitemselected(menuitem item) { ..... } }
and in listview of first activity
<listview android:id="@+id/lisview_id" // use id initialize listview android:layout_width="match_parent" android:layout_height="match_parent">
hope help
Comments
Post a Comment