android - Buttons not working with listview -
i have buttons across top of listview. buttons not function until select item list. according other posts, should add following line xml file: android:focusable="false". however, no change occurred after adding line.
here xml file:
<linearlayout android:layout_weight="2" android:layout_height="fill_parent" android:layout_width="match_parent" > <videoview android:id="@+id/video_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> </linearlayout> <linearlayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="16dp" android:layout_marginright="16dp" android:orientation="horizontal" > <button android:id="@+id/chapters" android:layout_width="wrap_content" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:focusable="false" android:text="@string/chapters" /> <button android:id="@+id/scales" android:layout_width="100dp" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:focusable="false" android:text="@string/scales" /> <button android:id="@+id/b_flat" android:layout_width="wrap_content" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/b_flat" /> <button android:id="@+id/e_flat" android:layout_width="75dp" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/e_flat" /> <button android:id="@+id/concert" android:layout_width="wrap_content" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/concert" /> <button android:id="@+id/bass" android:layout_width="75dp" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/bass" /> <button android:id="@+id/video" android:layout_width="wrap_content" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/video" /> <button android:id="@+id/practice" android:layout_width="wrap_content" android:layout_height="@dimen/btn_layout_height" android:textsize="@dimen/text_size" android:background="@drawable/button_custom" android:text="@string/practice" /> </linearlayout> <framelayout android:id="@+id/fragmentcontainer" android:layout_height="match_parent" android:layout_width="match_parent" /> </linearlayout>
here code use display list:
public class chapterlistfragment extends listfragment { private static final boolean verbose = true; private arraylist<chapters> mchapters; private static final string tag = "chapterlistfragment"; private button mchaptersbutton; @override public void oncreate(bundle savedinstancestate) { if (verbose) log.v(tag, "+++ oncreate +++"); super.oncreate(savedinstancestate); getactivity().settitle(r.string.chapters_title); mchapters = chapterlist.get(getactivity()).getchapters(); chapteradapter adapter = new chapteradapter(mchapters); setlistadapter(adapter); }
i updated "onlistitemclick following:
@override public void onlistitemclick(listview l, view v, int position, long id) { //if (verbose) log.v(tag, "+++ onlistitemclick +++"); // chapter adapter chapters c = ((chapteradapter)getlistadapter()).getitem(position); //start improvisationactivity intent = new intent(getactivity(), improvisationactivity.class); i.putextra(chapterfragment.extra_chapter_id, c.getid()); startactivity(i); } private class chapteradapter extends arrayadapter<chapters> { public chapteradapter(arraylist<chapters> chapters) { super(getactivity(), 0, chapters); } @override public view getview(int position, view convertview, viewgroup parent) { // if weren't given view, inflate 1 if (convertview == null) { convertview = getactivity().getlayoutinflater() .inflate(r.layout.list_item_chapter, null); } // configure view chapter chapters c = getitem(position); textview titletextview = (textview) convertview.findviewbyid(r.id.chapter_list_item_titletextview); titletextview.settext(c.getchapter()); return convertview; } } @override public void onresume() { super.onresume(); { ((chapteradapter)getlistadapter()).notifydatasetchanged(); } }
}
for having same problem, added following code activity , buttons have focus:
public class chapterlistactivity extends singlefragmentactivity { private static final boolean verbose = true; private static final string tag = "chapterlistactivity"; private button mchaptersbutton; @override public void oncreate(bundle savedinstancestate) { if (verbose) log.v(tag, "+++ oncreate +++"); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_improvisation); mchaptersbutton = (button)findviewbyid(r.id.chapters); // need default button pressed mchaptersbutton.setselected(true); mchaptersbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (mchaptersbutton.isselected()){ if (verbose) log.v(tag, "+++ onclick mchaptersbutton +++"); mchaptersbutton.setselected(false); toast.maketext(getapplicationcontext(), "chapters button not selected", toast.length_short).show(); } else { toast.maketext(getapplicationcontext(), "chapters button selected", toast.length_short).show(); mchaptersbutton.setselected(true); } } }); } @override protected fragment createfragment() { if (verbose) log.v(tag, "+++ createfragment +++"); return new chapterlistfragment(); }
}
your button
instantiated inside onlistitemclick
won't clickcable
until after click on list item. can move them oncreate()
need inflate
view
in there also, using setcontentview()
also, stated in comment buptcoder, don't see onclicklistener
attached button
. still don't see being clickable until after move out of listener in onclicklistener
still need attached button
Comments
Post a Comment