arrays - Combined display of EditText for Query with JSON Result to be able to scroll it -
need advice on how define screen able scroll result of json , attached :
package com.lm.vciwhereabout; import java.util.arraylist; import org.apache.http.namevaluepair; import org.apache.http.message.basicnamevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.app.activity; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.os.strictmode; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter; import android.widget.textview; import android.widget.adapterview.onitemclicklistener; public class querynameentry3 extends listactivity { edittext username; // take username input user button submit; textview tv; // textview show result of mysql query string returnstring; // store result of mysql query after decoding json /** called when activity first created. */ public void oncreate(bundle savedinstancestate) { strictmode.setthreadpolicy(new strictmode.threadpolicy.builder() .detectdiskreads().detectdiskwrites().detectnetwork() // strictmode commonly used catch accidental disk or network
access on application's main thread .penaltylog().build()); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_jsonuse);
setlistadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1)); username = (edittext) findviewbyid(r.id.edtxusername); submit = (button) findviewbyid(r.id.btnsubmit); tv = (textview) findviewbyid(r.id.showresult); // define action when user clicks on submit button submit.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { // declare parameters passed php script i.e. name "username" , value submitted user arraylist<namevaluepair> postparameters = new arraylist<namevaluepair>(); // define parameter postparameters.add(new basicnamevaluepair("username", username.gettext().tostring())); string response = null; // call executehttppost method passing necessary parameters try { response = customhttpclient.executehttppost( "http://192.168.0.245/vciwhereabout/waboutbyuser.php", // ip address if using localhost server postparameters); // store result returned php script runs mysql query string result = response.tostring(); //parse json data try{ returnstring = ""; jsonarray jarray = new jsonarray(result); for(int i=0;i<jarray.length();i++){ jsonobject json_data = jarray.getjsonobject(i); log.i("log_tag","post_id: "+json_data.getint("post_id")+ ", username: "+json_data.getstring("username")+ ", fdate: "+json_data.getstring("fdate")+ ", tdate: "+json_data.getstring("tdate")+ ", ftime: "+json_data.getstring("ftime")+ ", ttime: "+json_data.getstring("ttime")+ ", custbranch: "+json_data.getstring("custbranch")+ ", custname: "+json_data.getstring("custname")+ ", custaddr: "+json_data.getstring("custaddr")+ ", custcity: "+json_data.getstring("custcity")+ ", note: "+json_data.getstring("note") ); //get output screen returnstring += "username :" + json_data.getstring("username") + "\n" + "from date :" + json_data.getstring("fdate") + "\n" + "to date :" + json_data.getstring("tdate") + "\n" + "from time :" + json_data.getstring("ftime") + "\n" + "to time :" + json_data.getstring("ttime") + "\n" + "cust/branch :" + json_data.getstring("custbranch") + "\n" + "name :" + json_data.getstring("custname") + "\n" + "address :" + json_data.getstring("custaddr") + "\n" + "city :" + json_data.getstring("custcity") + "\n" + "note :" + json_data.getstring("note") + "\n" + "-------------------------------------------" ; } } catch(jsonexception e){ log.e("log_tag", "error parsing data "+e.tostring()); } try{ tv.settext(returnstring); } catch(exception e){ log.e("log_tag","error in display!" + e.tostring());; } } catch (exception e) { log.e("log_tag","error in http connection!!" + e.tostring()); } } }); } private void setlistadapter(arrayadapter<string> arrayadapter) { // todo auto-generated method stub } }
and layout activity_jsonuse.xml :
<textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="staff name query" /> <edittext android:id="@+id/edtxusername" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="text" > </edittext> <button android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="submit" android:layout_gravity="center" /> <textview android:id="@+id/showresult" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="result" /> <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </linearlayout>
on make output screen, how defined / changed it, can scroll results ?
since have define layout query edittext, make or call new layout display result scroll capability ( in 1 .java activities) ? please guide me on code above.
thanks lot (i'm new on android , programming).
with addition of scrollview attached , solved. virtual keyboard still appear after displaying result. how removed virtual keyboard automatically, after result appeared on screen ? thanks.
<scrollview > android:layout_width="fill_parent" > android:lines="20" > android:layout_height="390dip" > > <textview > android:id="@+id/showresult2" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:singleline="false" > android:textappearance="?android:attr/textappearancelarge" > > android:paddingbottom="2dip" > android:paddingleft="45dip" > android:textcolor="#5d5d5d" > > /> > > </scrollview>
with addition of scrollview attched, solved problem.
<scrollview > android:layout_width="fill_parent" > android:lines="20" > android:layout_height="390dip" > > <textview > android:id="@+id/showresult2" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > android:singleline="false" > android:textappearance="?android:attr/textappearancelarge" > > android:paddingbottom="2dip" > android:paddingleft="45dip" > android:textcolor="#5d5d5d" > > /> > > </scrollvi
ew>
Comments
Post a Comment