gpt4 book ai didi

Android - fragment 中的 ListView

转载 作者:行者123 更新时间:2023-11-30 01:20:34 27 4
gpt4 key购买 nike

我正在尝试解析 RSS 提要并通过 fragment 中的 Listview 将其显示给用户。问题是列表中没有显示任何内容,我收到了一些错误:

V/Error Parsing Data: java.io.IOException: Couldn't open http://feeds.bbci.co.uk/news/england/rss.xml
W/FragmentManager: moveToState: Fragment state for Thingy{3633e4e #1 id=0x7f0c0069} not updated inline; expected state 3 found 2

我的 fragment 类:

public class Thingy extends Fragment {
ListView mList;
ArrayAdapter<String> adapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.fragment_main, container, false);
adapter = new ArrayAdapter<>(getActivity(), R.layout.basic_list_item);
mList = ((ListView) v.findViewById(R.id.listView));
new GetRssFeed().execute("http://feeds.bbci.co.uk/news/england/rss.xml");

return v;
}

private class GetRssFeed extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
adapter.add("Pizza Steak");
try {
RssReader rssReader = new RssReader(params[0]);
for (RssItem item : rssReader.getItems()) {
adapter.add(item.getTitle());
}
} catch (Exception e) {
Log.v("Error Parsing Data", e + "");
}
return null;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter.notifyDataSetChanged();
mList.setAdapter(adapter);
}
}
}

最佳答案

请在 list 上添加权限

<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>

关于Android - fragment 中的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37169556/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com