Last active
August 29, 2015 14:13
-
-
Save AndrewWang1993/cb03a3497b0408c60d67 to your computer and use it in GitHub Desktop.
以流的形式从URL获得XML信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XmlPullParser xmlPullParser = null; | |
try { | |
InputStream is = util.getInput("http://121.40.186.170/shipin/test1.php"); | |
XmlPullParserFactory pullFactory = XmlPullParserFactory.newInstance(); | |
xmlPullParser = pullFactory.newPullParser(); | |
xmlPullParser.setInput(is, "UTF-8"); | |
} catch (Exception e) { | |
Log.v("TAG", e.toString()); | |
} | |
ArrayList<Object> arrarys = util.ParseXml(xmlPullParser); | |
Log.v("TAG", arrarys.toString()); | |
ArrayList<HashMap<String, String[]>> mLishHash = util.process(arrarys); | |
Log.v("TAG", mLishHash.toString()); | |
imageUrls = util.getGridDescOrPic(mLishHash, "pics", false); | |
Log.v("TAG", imageUrls.toString()); | |
public static String[] getGridDescOrPic(ArrayList<HashMap<String, String[]>> arrayListHash, String type, boolean descOrPic) { | |
int len = arrayListHash.size(); | |
Vector<String> vector = new Vector(); | |
for (int i = 0; i < len; i++) { | |
HashMap<String, String[]> hashMap = arrayListHash.get(i); | |
if (hashMap.containsKey(type)) { | |
if (descOrPic) { | |
vector.add(hashMap.get(type)[0]); | |
} else { | |
vector.add(hashMap.get(type)[1]); | |
} | |
} | |
} | |
String[] strings = new String[vector.size()]; | |
vector.toArray(strings); | |
return strings; | |
} | |
public static String[] getFlipPics(ArrayList<HashMap<String, String[]>> arrayListHash, int position) { | |
int len = arrayListHash.size(); | |
String type = "video"; | |
Vector<String> vector = new Vector<String>(); | |
String []strings = new String[0]; | |
for (int i = 0; i < len; i++) { | |
HashMap<String, String[]> hashMap = arrayListHash.get(i); | |
if (hashMap.containsKey(type) && --position == 0) { | |
int picLen=hashMap.get(type).length; | |
for (int j=1;j<picLen;j++){ | |
vector.add(0,hashMap.get(type)[j]); | |
} | |
strings=new String[picLen-1]; | |
vector.toArray(strings); | |
} | |
} | |
return strings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment