Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以让我们使用jsoup从网页获取数据,并在android中将其显示为listview?_Android_Jsoup - Fatal编程技术网

有没有一种方法可以让我们使用jsoup从网页获取数据,并在android中将其显示为listview?

有没有一种方法可以让我们使用jsoup从网页获取数据,并在android中将其显示为listview?,android,jsoup,Android,Jsoup,我正在尝试使用Jsoup从网页获取数据列表,并希望ot在我的android应用程序中显示为列表视图。我已获得数据,但无法在列表视图中进行设置 public class BollywoodFragment extends Fragment { ListView bollyList; TextView text1; ArrayList<String> list = new ArrayList<String>(); ArrayAdapter<String>arra

我正在尝试使用Jsoup从网页获取数据列表,并希望ot在我的android应用程序中显示为列表视图。我已获得数据,但无法在列表视图中进行设置

public class BollywoodFragment extends Fragment {

ListView bollyList;
TextView text1;
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String>arrayAdapter;

StringBuilder bollyMovies = new StringBuilder();

public BollywoodFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_bollywood, container, false);
    text1= (TextView)view.findViewById(R.id.text1);
    bollyList = (ListView)view.findViewById(R.id.bollyList);

    new bolly().execute("https://right2see.home.blog/bollywood/");
    return view;
}
class bolly extends AsyncTask<String,String,String>{
    String words;
    @Override
    protected String doInBackground(String... strings) {

        try {
            String url = "https://right2see.home.blog/bollywood/";
            Document document = Jsoup.connect(url).get();
            Elements elements = document.select("div.post-content.clear");
            for(Element element:elements){
                bollyMovies.append(element.getElementsByTag("a").text());
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        text1.setText(bollyMovies);
    }
}
我从网页中获取了数据,并将其存储在字符串生成器中,因为我无法将其存储在列表视图中

public class BollywoodFragment extends Fragment {

ListView bollyList;
TextView text1;
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String>arrayAdapter;

StringBuilder bollyMovies = new StringBuilder();

public BollywoodFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_bollywood, container, false);
    text1= (TextView)view.findViewById(R.id.text1);
    bollyList = (ListView)view.findViewById(R.id.bollyList);

    new bolly().execute("https://right2see.home.blog/bollywood/");
    return view;
}
class bolly extends AsyncTask<String,String,String>{
    String words;
    @Override
    protected String doInBackground(String... strings) {

        try {
            String url = "https://right2see.home.blog/bollywood/";
            Document document = Jsoup.connect(url).get();
            Elements elements = document.select("div.post-content.clear");
            for(Element element:elements){
                bollyMovies.append(element.getElementsByTag("a").text());
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        text1.setText(bollyMovies);
    }
}
公共类宝莱坞碎片扩展片段{
ListView-bollyList;
TextView text1;
ArrayList=新建ArrayList();
ArrayAdapterarrayAdapter;
StringBuilder bollyMovies=新的StringBuilder();
公共宝莱坞碎片(){
//必需的空公共构造函数
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//为该碎片膨胀布局
视图=充气机。充气(R.layout.fragment\u宝莱坞,容器,假);
text1=(TextView)view.findViewById(R.id.text1);
bollyList=(ListView)view.findViewById(R.id.bollyList);
新建bolly()。执行(“https://right2see.home.blog/bollywood/");
返回视图;
}
类bolly扩展了异步任务{
字符串;
@凌驾
受保护的字符串背景(字符串…字符串){
试一试{
字符串url=”https://right2see.home.blog/bollywood/";
Document Document=Jsoup.connect(url.get();
Elements=document.select(“div.post-content.clear”);
for(元素:元素){
append(element.getElementsByTag(“a”).text());
}
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
text1.setText(bollyMovies);
}
}
}


以上代码在文本视图中显示正确的输出。但是我希望在列表视图中输出,有什么方法可以这样做吗?

您可以创建
电影
对象,然后将它们绑定到
列表视图

您可以在此处阅读更多内容:


你就快到了--你只需要做数据绑定。如果只需要显示这个和那个,也可以使用字符串

你已经走到一半了。创建列表视图,然后将数据集合绑定到列表视图——应该就是这样。不要将所有内容都添加到stringbuilder中,而是将每个列表项添加到列表中,然后将该列表设置为ListView的源