Android Flyout Menu not visible -
i not able view flyout menu. when swipe left right needs force listview right , create flyout menu appear not appear.
can know reason ?
the code appears below :
activity_sample.xml
<com.sri.vaave2.flyoutcontainer xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#444488" android:orientation="vertical" > <button android:layout_width="match_parent" android:layout_height="wrap_content" android:onclick="togglemenu" android:text="news" /> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:onclick="togglemenu" android:text="jobs" /> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:onclick="togglemenu" android:text="internships" /> </linearlayout> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#888888" android:orientation="vertical" android:gravity="center" > <!-- <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="hello" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="togglemenu" android:text="toggle menu" /> --> <listview android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@null" /> </linearlayout> </com.sri.vaave2.flyoutcontainer>
mainactivity.java
package com.sri.vaave2; import java.io.unsupportedencodingexception; import java.util.arraylist; import java.util.iterator; import java.util.list; import org.json.jsonexception; import org.json.jsonobject; import com.android.volley.cache; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.volleylog; import com.android.volley.cache.entry; import com.android.volley.request.method; import com.android.volley.toolbox.jsonobjectrequest; import com.sri.vaave2.mainactivity; import com.sri.vaave2.app.appcontroller; import com.sri.vaave2.adapter.feedlistadapter; import com.sri.vaave2.data.feeditem; import com.sri.vaave2.r; import android.app.activity; import android.content.context; import android.content.intent; import android.os.bundle; import android.view.gesturedetector; import android.view.gesturedetector.simpleongesturelistener; import android.view.menu; import android.view.menuitem; import android.view.motionevent; import android.view.view; import android.view.view.ontouchlistener; import android.widget.listview; public class mainactivity extends activity implements ontouchlistener { private static final string tag = mainactivity.class.getsimplename(); private listview listview; private feedlistadapter listadapter; private list<feeditem> feeditems; private string url_feed = "http://coherendz.net/vaavefeed1.json"; flyoutcontainer root; iterator<?> itr; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // setcontentview(r.layout.activity_main); this.root = (flyoutcontainer) this.getlayoutinflater().inflate(r.layout.activity_sample, null); this.setcontentview(root); root.setontouchlistener(this); feeditems = new arraylist<feeditem>(); feeditems= getdata(0); listadapter = new feedlistadapter(this, feeditems); listview = (listview) findviewbyid(r.id.list); listview.setadapter(listadapter); listadapter.notifydatasetchanged(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, 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.profile) { intent p = new intent(getapplicationcontext(),actionprofile.class); startactivity(p); } else if(id== r.id.feed) { intent f = new intent (getapplicationcontext(),feed.class); startactivity(f); } else if (id == r.id.posting){ intent po = new intent (getapplicationcontext(),posting.class); startactivity(po); } homecoming super.onoptionsitemselected(item); } public void togglemenu(view v){ this.root.togglemenu(); } /** * detects left , right swipes across view. */ public class onswipetouchlistener implements ontouchlistener { private final gesturedetector gesturedetector; public onswipetouchlistener(context context) { gesturedetector = new gesturedetector(context, new gesturelistener()); } public void onswipeleft() { } public void onswiperight() { } public boolean ontouch(view v, motionevent event) { homecoming gesturedetector.ontouchevent(event); } private final class gesturelistener extends simpleongesturelistener { private static final int swipe_distance_threshold = 100; private static final int swipe_velocity_threshold = 100; @override public boolean ondown(motionevent e) { homecoming true; } @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { float distancex = e2.getx() - e1.getx(); float distancey = e2.gety() - e1.gety(); if (math.abs(distancex) > math.abs(distancey) && math.abs(distancex) > swipe_distance_threshold && math.abs(velocityx) > swipe_velocity_threshold) { if (distancex > 0) onswiperight(); else onswipeleft(); homecoming true; } homecoming false; } } } @override public boolean ontouch(view v, motionevent event) { // todo auto-generated method stub togglemenu(v); homecoming false; } private list<feeditem> getdata(int nodetype) { // todo auto-generated method stub // first check cached request cache cache = null; cache = appcontroller.getinstance().getrequestqueue().getcache(); entry entry = cache.get(url_feed); string info = null; if (entry != null) { // fetch info cache seek { info = new string(entry.data, "utf-8"); seek { parsejsonfeed(new jsonobject(data)); } grab (jsonexception e) { e.printstacktrace(); } } grab (unsupportedencodingexception e) { e.printstacktrace(); } } else { // making fresh volley request , getting json jsonobjectrequest jsonreq = new jsonobjectrequest(method.get, url_feed, null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { volleylog.d(tag, "response: " + response.tostring()); if (response != null) { parsejsonfeed(response); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); } }); // adding request volley request queue appcontroller.getinstance().addtorequestqueue(jsonreq); } homecoming feeditems; } /** * parsing json reponse , passing info feed view list adapter * */ private void parsejsonfeed(jsonobject response) { feeditem item; itr = response.keys(); seek { while(itr.hasnext()) { string key = itr.next().tostring(); jsonobject entry = response.getjsonobject(key); jsonobject phone = entry.getjsonobject("basic"); string name = phone.getstring("title"); string description = phone.getstring("description"); int nodetype = phone.getint("node_type"); jsonobject comments = entry.getjsonobject("comments"); string comments_count = comments.getstring("count"); jsonobject = entry.getjsonobject("likes"); string like_count = like.getstring("count"); string readable_date = phone.getstring("readable_date"); item = new feeditem(); item.setnode_type(nodetype); item.setname(string.valueof(name)); item.setstatus(string.valueof(description)); item.setreadable_date(string.valueof(readable_date)); item.setcomments_count(string.valueof(comments_count)); item.setlike_count(string.valueof(like_count)); feeditems.add(item); } } grab (jsonexception e) { e.printstacktrace(); } } }
i have solved problem.
the code below :
listview.setontouchlistener(new onswipetouchlistener(this){
@override public void onswiperight() { // whatever toast.maketext(mainactivity.this, "right", toast.length_short).show(); togglemenu(listview); }
});
android android-listview
No comments:
Post a Comment