Iam new to android. Flipper only displays the first xml item

Put your problem here if it does not fit any of the other categories.

Iam new to android. Flipper only displays the first xml item

Postby Msrn » Mon Feb 28, 2011 7:08 am

Kindly code the exact way it should be coded. XMl also gien below. Please helo me immediately.
Next value not got from loop swipe. help me immediately.

Sent: Thu Feb 24, 2011 12:14 pm
From: Msrn
To: madmax plusminus
package com.androidparsing.xml.parsing;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class XMLParsingDOMExample extends Activity{
int length=0;
int i;
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper viewFlipper;
@Override
public void onCreate(Bundle savedInstanceState) {
int length = 1;
int i = 0;

super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.main_1,
(ViewGroup) findViewById(R.id.layout_root));
// final View titlelayout = inflater.inflate(R.layout.title,
//(ViewGroup) findViewById(R.id.layout_root2));
//final TextView title = (TextView)titlelayout.findViewById(R.id.myTitle);
//setTitle(title.getText());


final TextView inpu = (TextView)layout.findViewById(R.id.text5);
final TextView aliasname = (TextView)layout.findViewById(R.id.text);
final TextView term = (TextView)layout.findViewById(R.id.text1);
final TextView category = (TextView)layout.findViewById(R.id.text2);
final TextView description = (TextView)layout.findViewById(R.id.text3);
final TextView termclass = (TextView)layout.findViewById(R.id.text4);
final TextView available = (TextView)layout.findViewById(R.id.text6);
final TextView dont = (TextView)layout.findViewById(R.id.text7);
final TextView contains = (TextView)layout.findViewById(R.id.text8);
final TextView sideeffects = (TextView)layout.findViewById(R.id.text9);
final TextView nodrug = (TextView)layout.findViewById(R.id.text10);

setContentView(layout);
//final Button button = (Button) findViewById(R.id.ok);

try
{
URL url = new URL("http://www.icube-solutions.com/example.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
final NodeList nodeList = doc.getElementsByTagName("item");
length = nodeList.getLength();
inpu.setText("ddd");
//System.out.println("length..........."+length);
for(i=0;i<length;i++){

Node node = nodeList.item(i);
inpu.setText("ddd");
Element fstElmnt = (Element ) node;
NodeList categoryList = fstElmnt.getElementsByTagName("term");
Element categoryElement = (Element) categoryList.item(i);
String cat = (categoryElement.getAttribute("category")).toString();
category.setText(cat);

NodeList nameList = fstElmnt.getElementsByTagName("aliasname");
Element nameElement = (Element) nameList.item(i);
nameList = nameElement.getChildNodes();
aliasname.setText(((Node) nameList.item(i)).getNodeValue());

NodeList websiteList = fstElmnt.getElementsByTagName("term");
Element websiteElement = (Element) websiteList.item(i);
websiteList = websiteElement.getChildNodes();
term.setText(((Node) websiteList.item(i)).getNodeValue());

NodeList descList = fstElmnt.getElementsByTagName("description");
Element descElement = (Element) descList.item(i);
descList = descElement.getChildNodes();
description.setText(((Node) descList.item(i)).getNodeValue());

NodeList itcList = fstElmnt.getElementsByTagName("termclass");
Element itcElemnet = (Element) itcList.item(i);
itcList = itcElemnet.getChildNodes();
termclass.setText(((Node) itcList.item(i)).getNodeValue());

NodeList availList = fstElmnt.getElementsByTagName("available");
Element availElemnet = (Element) availList.item(i);
availList = availElemnet.getChildNodes();
available.setText(((Node) availList.item(i)).getNodeValue());

NodeList dontList = fstElmnt.getElementsByTagName("dont");
Element dontElemnet = (Element) dontList.item(i);
dontList = dontElemnet.getChildNodes();
dont.setText(((Node) dontList.item(i)).getNodeValue());

NodeList containsList = fstElmnt.getElementsByTagName("contains");
Element containsElemnet = (Element) containsList.item(i);
containsList = containsElemnet.getChildNodes();
contains.setText(((Node) containsList.item(i)).getNodeValue());

NodeList sideeffectsList = fstElmnt.getElementsByTagName("sideeffects");
Element sideeffectsElemnet = (Element) sideeffectsList.item(i);
sideeffectsList = sideeffectsElemnet.getChildNodes();
sideeffects.setText(((Node) sideeffectsList.item(i)).getNodeValue());

NodeList nodrugList = fstElmnt.getElementsByTagName("nodrug");
Element nodrugElemnet = (Element) nodrugList.item(i);
nodrugList = nodrugElemnet.getChildNodes();
nodrug.setText(((Node) nodrugList.item(i)).getNodeValue());
//System.out.println("ssssssssss");
}

}
catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}


viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
class MyGestureDetector extends SimpleOnGestureListener {


@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();

} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
}
} catch (Exception e) {
// nothing
}
return false;
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}
}

my xml is

<maintag>
<item>
<aliasname>Enalapril</aliasname>
<term category ="Vasotec">It is an ACE Inhibitor</term>
<description>Used in Treatment Of Hypertension</description>
<termclass>10 to 40 mg po qd</termclass>
<available>sssssssssssss</available>
<dont>take with erythromycin</dont>
<contains>Contains phenylalnine, carefully prescribed to patients suffering from</contains>
<sideeffects>headache, constipatio</sideeffects>
<nodrug>xxxxxxxxx</nodrug>
</item>
<item>
<aliasname>Diazepam</aliasname>
<term category ="Vasotec">ACE Inhibitor</term>
<description>Used in Treatment Of Hypertension</description>
<termclass>10 to 40 mg po qd</termclass>
<available>sssssssssssss</available>
<dont>take with erythromycin</dont>
<contains>Contains phenylalnine, carefully prescribed to patients suffering from</contains>
<sideeffects>headache, constipatio</sideeffects>
<nodrug>xxxxxxxxx</nodrug>
</item>
<item>
<aliasname>Enfuvitide</aliasname>
<term category ="Vasotec">ACE Inhibitor</term>
<description>Treatment Of Hypertension</description>
<termclass>10 to 40 mg po qd</termclass>
<available>sssssssssssss</available>
<dont>take with erythromycin</dont>
<contains>Contains phenylalnine, carefully prescribed to patients suffering from</contains>
<sideeffects>headache, constipatio</sideeffects>
<nodrug>xxxxxxxxx</nodrug>
</item>
<item>
<aliasname>Gleevee</aliasname>
<term category ="Vasotec">ACE Inhibitor</term>
<description>Treatment Of Hypertension</description>
<termclass>10 to 40 mg po qd</termclass>
<available>sssssssssssss</available>
<dont>take with erythromycin</dont>
<contains>Contains phenylalnine, carefully prescribed to patients suffering from</contains>
<sideeffects>headache, constipatio</sideeffects>
<nodrug>xxxxxxxxx</nodrug>
</item>
</maintag>
Msrn
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 24, 2011 12:31 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 22 guests