Professional Documents
Culture Documents
Drug Result Code
Drug Result Code
getExtras();
searchcode=gotBundle.getString("searchcode");
JParse jsonParse = new JParse();
jsonParse.execute();
}
return json;
@Override
protected void onPostExecute(JSONObject json){
// TODO Auto-generated method stub
super.onPostExecute(json);
try {
Drug = json.getJSONArray(TAG_OBJ);
for (int i = 0; i < Drug.length(); i++) {
JSONObject c = Drug.getJSONObject(i);
String drugName = c.getString(TAG_NAME);
if(drugName.length()!=0)
Name.setText(drugName);
else
Name.setText("Not Available");
String drugcode=c.getString(TAG_CODE);
if(drugcode.length()!=0)
Code.setText(drugcode);
else
Code.setText("Not Available");
String drugMan =
c.getString(TAG_MANUFACTURER);
if(drugMan.length()!=0)
Manufacturer.setText(drugMan);
else
Manufacturer.setText("Not Available");
String drugPacking = c.getString(TAG_PACKING);
if(drugPacking.length()!=0)
Package.setText(drugPacking);
else
Package.setText("Not Available");
String drugCost = c.getString(TAG_COST);
if(drugCost.length()!=0)
Cost.setText(drugCost);
else
Cost.setText("Not Available");
String drugTax = c.getString(TAG_TAX);
if(drugTax.length()!=0)
Tax.setText(drugTax);
else
Tax.setText("Not Available");
String drugContent = c.getString(TAG_CONTENT);
if(drugContent.length()!=0)
Constituent.setText(drugContent);
else
Constituent.setText("Not Available");
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
----------------------------------------------------------------------------------
}
catch(UnsupportedEncodingException e){
e.printStackTrace();
}
catch(ClientProtocolException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
try{
BufferedReader br = new BufferedReader(new
InputStreamReader(inputstream,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while((line = br.readLine())!=null){
sb.append(line);
}
inputstream.close();
json = sb.toString();
}
catch(Exception e){
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try{
jObj = new JSONObject(json);
}
catch(JSONException e){
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
@Override
protected JSONObject doInBackground(String... arg0) {
// TODO Auto-generated method stub
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromURL(gotSearchType,
gotSearchText);
return json;
}
String>();
@Override
protected void onPostExecute(JSONObject json) {
// TODO Auto-generated method stub
super.onPostExecute(json);
try {
Drug = json.getJSONArray(TAG_OBJ);
for (int i = 0; i < Drug.length(); i++) {
JSONObject c = Drug.getJSONObject(i);
String drugName = c.getString(TAG_NAME);
String drugStrength = c.getString(TAG_STRENGTH);
String drugMan = c.getString(TAG_MANUFACTURER);
String prepType = c.getString(TAG_PREPTYPE);
String drugCost = c.getString(TAG_COST);
HashMap<String, String> map = new HashMap<String,
map.put(TAG_NAME, drugName);
map.put(TAG_STRENGTH, drugStrength);
map.put(TAG_MANUFACTURER, drugMan);
map.put(TAG_PREPTYPE, prepType);
map.put(TAG_COST, drugCost);
druglist.add(map);
list = (ListView) findViewById(R.id.resultList);
ListAdapter adapter = new
SimpleAdapter(ListResult.this,
TAG_MANUFACTURER,
R.id.tvName,
R.id.tvStrength,
R.id.tvMAnufacturer,
R.id.tvType,
R.id.tvPrice });
list.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
DrugResult.xml add
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:id="@+id/titleCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Code"
android:visibility="invisible"/>"
<TextView
android:id="@+id/valueCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:gravity="left"
android:text="4.00"
android:visibility="invisible"/>"
</LinearLayout>
ListResult old
package com.example.gdf;
import java.util.ArrayList;
import java.util.HashMap;
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.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
ListView list;
TextView drugCode;
TextView drugName;
TextView drugPacking;
TextView drugMan;
//TextView prepType;
TextView drugCost;
//TextView drugCompare;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
@Override
protected void onPreExecute() {
super.onPreExecute();
drugCode.setVisibility(View.INVISIBLE);
@Override
protected JSONObject doInBackground(String... arg0) {
// TODO Auto-generated method stub
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromURL(gotSearchType,
gotSearchText);
return json;
}
}*/
@Override
protected void onPostExecute(JSONObject json) {
// TODO Auto-generated method stub
super.onPostExecute(json);
try {
Drug = json.getJSONArray(TAG_OBJ);
for (int i = 0; i < Drug.length(); i++) {
JSONObject c = Drug.getJSONObject(i);
String drugName = c.getString(TAG_NAME);
String drugcode=c.getString(TAG_CODE);
//
String drugMan =
c.getString(TAG_MANUFACTURER);
String drugPacking = c.getString(TAG_PACKING);
String drugCost = "Rs. " + c.getString(TAG_COST);
list.setAdapter(adapter);
//
drugCode.setVisibility(View.INVISIBLE);
/*
list.setOnItemClickListener(new
OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?>
arg0, View arg1,
int arg2, long arg3) {
String
getCode=drugCode.getText().toString();
selectActivity(getCode);
// TODO Auto-generated method stub
});
*/
} catch (JSONException e) {
e.printStackTrace();
}
}
}
<Button
android:id="@+id/Rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:background="@drawable/rounded"
android:padding="15dp"
android:radius="10dp"
android:text="Rate Me"
android:textSize="15dp"/>
<Button
android:id="@+id/Information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="@drawable/rounded"
android:padding="15dp"
android:textSize="15dp"
android:text="Find Me" />