public class
CocktailIndexActivity extends Activity{ NetworkXMLActivity
ab = new NetworkXMLActivity(); public
void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); loadList(); } public
void reLoadList(View view){ loadList(); } HashMap<String,
String> hm = new HashMap<String, String>(); public
void loadList(){ String
theUrl = "http://tierro.cafe24.com/cok/list1.xml"; cmsHTTP
cmshttp = new cmsHTTP(); cmshttp.encoding
= "UTF-8"; cmshttp.act
= this; String
tmpData = cmshttp.sendGet(theUrl); if(tmpData==null)
return; hm
= xml2HashMap(tmpData, "UTF-8"); theListAdapter
listAdapter = new theListAdapter(this, R.layout.list_row1, hm); ListView
listView = (ListView) findViewById(R.id.listView1); listView.setAdapter(listAdapter); }
public
HashMap<String, String> xml2HashMap(String tmpData, String encoding){ HashMap<String,
String> hm = new HashMap<String, String>(); hm.put("count",
"0"); try{ DocumentBuilderFactory
docBF = DocumentBuilderFactory.newInstance(); DocumentBuilder
docB = docBF.newDocumentBuilder(); InputStream
is = new ByteArrayInputStream(tmpData.getBytes(encoding)); Document doc =
docB.parse(is); Element
lists = doc.getDocumentElement(); NodeList
dataList = lists.getElementsByTagName("data"); int
c = 0; for(int
i = 0; i<dataList.getLength(); i++){ NodeList
dataNodeList = dataList.item(i).getChildNodes(); for(int
j=0; j<dataNodeList.getLength(); j++){ Node
itemNode = dataNodeList.item(j); if(itemNode.getFirstChild()
!= null){ String
nodeName = itemNode.getNodeName(); String
nodeValue = itemNode.getFirstChild().getNodeValue(); hm.put(nodeName
+ "[" + i + "]", nodeValue); } } c++; } hm.put("count",
Integer.toString(c)); }catch
(Exception e){ Log.e("com.cms.sample.xml2HashMap",
e.getMessage()); } return
hm; } class
theListAdapter extends BaseAdapter{ LayoutInflater
inflater; HashMap<String,
String>hm; Context
mContext; int
mListLayout; public
int listCount = 0; public
theListAdapter(Context tContext, int listLayout, HashMap <String,
String>tmpHm){ mContext
= tContext; mListLayout
= listLayout; hm
= tmpHm; inflater
= (LayoutInflater)mContext. getSystemService(Context.LAYOUT_INFLATER_SERVICE); listCount
= Integer.parseInt(hm.get("count").toString()); }
public
theListAdapter(NetworkXMLActivity networkXMLActivity, int
listRow1, HashMap<String, String> hm2) { //
TODO Auto-generated constructor stub }
public
int getCount() { //
TODO Auto-generated method stub return
listCount; }
public
Object getItem(int arg0) { //
TODO Auto-generated method stub return
arg0; }
public
long getItemId(int position) { //
TODO Auto-generated method stub return
position; } public
HashMap<String, Bitmap>hmImg= new HashMap<String, Bitmap>(); public
View getView(int position, View convertView, ViewGroup parent) { if(convertView
== null){ convertView
= inflater.inflate(mListLayout, parent, false); } try{ if(hmImg.get("thumb["
+ position + "]") == null){ String
urlstr = hm.get("thumb[" + position + "]"); URL
url = new URL("urlstr); URLConnection
conn = url.openConnection(); conn.connect(); BufferedInputStream
bis = new BufferedInputStream(conn. getInputStream(),
512 * 1024); Bitmap
bm = BitmapFactory.decodeStream(bis); bis.close(); hmImg.put("thumb["
+ position + "]", bm); } if
(hmImg.get("thumb[" + position + "]") != null){ ((ImageView)
convertView.findViewById(R.id.imageView1)) .setImageBitmap(hmImg.get("thumb["
+ position + "]")); public
void reLoadList1(View view){
ab.loadList();
}