我的代码如下:
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
String xml = ParseXMLMethods.getXML();
Document doc = ParseXMLMethods.XMLfromString(xml);
NodeList children = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < children.getLength(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)children.item(i);
map.put("PID", ParseXMLMethods.getValue(e, KEY_ID));
map.put("Passionname", ParseXMLMethods.getValue(e, KEY_TITLE));
map.put("Progress", ParseXMLMethods.getValue(e,KEY_PROGRESS));
Log.d("Progress",ParseXMLMethods.getValue(e,KEY_PROGRESS));
map.put("Duedate", ParseXMLMethods.getValue(e, KEY_DUEDATE));
map.put("Action", ParseXMLMethods.getValue(e, KEY_ACTION));
mylist.add(map);
}
adapter = new SimpleAdapter(getBaseContext(), mylist , R.layout.row,
new String[] { KEY_TITLE,KEY_PROGRESS,KEY_DUEDATE,KEY_ACTION},
new int[] {R.id.txt,R.id.progress, R.id.FROM_CELL, R.id.del_btn})
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
return itemView;
}
};
adapter.setViewBinder(new MyBinder());
list.setAdapter(adapter);
list.setItemsCanFocus(true);
我的ViewBinder类如下:
class MyBinder implements ViewBinder{
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if(view.getId() == R.id.progress){
String stringval = (String) data;
int progressValue = Integer.parseInt(stringval);
ProgressBar progressbar = (ProgressBar) view;
progressbar.setProgress(progressValue);
Resources res = getResources();
Rect bounds = progressbar.getProgressDrawable().getBounds();
if(progressValue==100)
{
progressbar.setProgressDrawable(res.getDrawable(R.drawable.red_progressbar));
}
else
{
progressbar.setProgressDrawable(res.getDrawable(R.drawable.green_progreesbar));
}
progressbar.getProgressDrawable().setBounds(bounds);
return true;
}
return false;
}
}
每当运行上面的代码时出现以下错误:
12-01 04:55:37.162:E / AndroidRuntime(3478):java.lang.NumberFormatException:无效的int:“50” 12-01 04:55:37.162:E / AndroidRuntime(3478):at java.lang.Integer.invalidInt(Integer.java:137) 12-01 04:55:37.162:E / AndroidRuntime(3478):at java.lang.Integer.parse(Integer.java:374)
但是这个代码在我的进度条使用静态数组时运行成功。请帮助我......
答案 0 :(得分:0)
这里的问题在于下面给出的XML文件的数据 无效的int:&#34; 50&#34;。在我的xml文件中50后存在空格,这就是我收到错误的原因。我这个问题浪费了3个小时。