が表示されないという問題がありListView
ます。エラーは発生せず、背景画像やその他のテキストは表示されますが、ListView
は表示されません。デバッグしてもエラーが見つかりません。
問題が何であるか手がかりはありますか?
public class MainActivity extends Activity {
List<String> sermon;
List<String> links;
ArrayAdapter<String> adapter;
private ListView list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView);
sermon = new ArrayList<String>();
links = new ArrayList<String>();
adapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1, sermon);
new PostTask(this).execute("http://gibk.se/sample-page/predikningar/?podcast");
}
public class PostTask extends AsyncTask<String, Long, String> {
private Context context;
public PostTask(Context context) {
this.context = context;
}
private InputStream getInputStream(URL url) {
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}
@Override
protected String doInBackground(String... params) {
try {
String url = params[0];
URL urls = new URL(url);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xmlParser = factory.newPullParser();
xmlParser.setInput(getInputStream(urls), "UTF_8");
boolean insideItem = false;
int eventType = xmlParser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xmlParser.getName().equalsIgnoreCase("item")) {
insideItem = true;
} else if (xmlParser.getName().equalsIgnoreCase("title")) {
if (insideItem)
sermon.add(xmlParser.nextText());
} else if (xmlParser.getName().equalsIgnoreCase("guid")) {
if (insideItem)
links.add(xmlParser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG
&& xmlParser.getName().equalsIgnoreCase("item")) {
insideItem = false;
}
eventType = xmlParser.next();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
protected void onPostExecute(String result) {
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
Uri uri = Uri.parse(links.get(position));
String url = uri.toString();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
}
}