RSS 피드가 웹 사이트에서로드되어 목록보기에 표시되는 활동이 있습니다. 것은 목록보기에 물건을로드하는 데 몇 초가 걸립니다. 그리고 나는 데이터로드에 관해 사용자에게 알리기 위해 progressbar를 구현하려고한다. 다음은 listview를로드하는 동안 진행률 막대를 구현하는 방법은 무엇입니까? - android
는public class RSS extends ListActivity {
List<String> headlines;
List<String> links;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rss);
// Initializing instance variables
headlines = new ArrayList<String>();
links = new ArrayList<String>();
try {
URL url = new URL("http://feeds.pcworld.com/pcworld/latestnews");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
// We will get the XML from an input stream
xpp.setInput(getInputStream(url), "UTF_8");
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("item")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Binding data
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
}
private InputStream getInputStream(URL url) {
// TODO Auto-generated method stub
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
Uri uri = Uri.parse((String) links.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
그래서 누군가가 데이터를로드 할 때 간단한 진행 막대를 구현하는 저를 도울 수 있습니다 .. RSS를 표시하는 코드 피드입니까? :)
어떻게하면 목록보기로 어댑터를 새로 고칠 수 있습니까? – kumareloaded
LoaderTask의 생성자에서 어댑터에 대한 참조를 전달하십시오. 그럼'onProgressUpdate'에서'adapter.notifyDatasetChanged()' – AedonEtLIRA
으로 충분합니까? 진행률 표시 줄은 어디에 사용해야합니까? RSS 또는 LoadingTask에서? – kumareloaded