Android ListView适配器出现问题

Android ListView适配器出现问题,android,listview,jsoup,Android,Listview,Jsoup,当我注释掉“nameAdapter=…”或“numAdapter=…”的代码并保持另一个未注释时,它将在listview中显示数据。因此,它能够分别显示这两个,但是,当我将这两个都保留为未注释状态时,它将只显示与numAdapter相关的数据。可能是个简单的错误,但我不知道哪里出了错 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

当我注释掉“nameAdapter=…”或“numAdapter=…”的代码并保持另一个未注释时,它将在listview中显示数据。因此,它能够分别显示这两个,但是,当我将这两个都保留为未注释状态时,它将只显示与numAdapter相关的数据。可能是个简单的错误,但我不知道哪里出了错

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.player);

    lv = (ListView) findViewById(R.id.listView);

    new Logo().execute();
    new statistics().execute();
    nameAdapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.stat_name,statName);
    numAdapter = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.stat_number,statNum);

}

private class statistics extends AsyncTask<String, Void, String> {
    //final ListView listview = (ListView) findViewById(R.id.listView);
    /*String[] values = new String[]{ "Ball Control", "Crossing", "Curve",
            "Dribbling", "Finishing", "Free Kick Accuracy", "Heading Accuracy", "Long Passing",
            "Long Shots", "Marking", "Penalties", "Short Passing", "Shot Power", "Sliding Tackle",
            "Standing Tackle", "Volleys"};*/
    //String[] stats = new String[16];
    @Override
    protected String doInBackground(String... arg) {
        Document document;
        try {
            document = Jsoup.connect(url).get();
            num = document.select("div#stats-base p");
            statNum.clear();
            for (Element element : num) {
                statNum.add(element.ownText());
            }
            name = document.select("div#stats-base span");
            statName.clear();
            for (Element element : name) {
                statName.add(element.ownText());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }
    @Override
    protected void onPostExecute(String result) {

        lv.setAdapter(nameAdapter);
        lv.setAdapter(numAdapter);
    }
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
lv=(ListView)findViewById(R.id.ListView);
新徽标().execute();
新统计信息().execute();
nameAdapter=newArrayAdapter(this,R.layout.simple_list_item_1,R.id.stat_name,statName);
numAdapter=new ArrayAdapter(这个,R.layout.simple\u list\u item\u 1,R.id.stat\u number,statNum);
}
私有类统计扩展了异步任务{
//最终ListView ListView=(ListView)findViewById(R.id.ListView);
/*字符串[]值=新字符串[]{“球控”、“交叉”、“曲线”,
“运球”、“射门”、“任意球精准度”、“头球精准度”、“长传”,
“远射”、“盯人”、“罚球”、“短传”、“射门能力”、“铲球”,
“立定铲球”、“截击”}*/
//String[]stats=新字符串[16];
@凌驾
受保护的字符串doInBackground(字符串…arg){
文件;
试一试{
document=Jsoup.connect(url.get();
num=document.select(“div#stats base p”);
statNum.clear();
for(元素:num){
add(element.ownText());
}
名称=文档。选择(“div#stats base span”);
statName.clear();
for(元素:名称){
statName.add(element.ownText());
}
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(字符串结果){
lv.setAdapter(名称适配器);
低压设置适配器(numAdapter);
}
}
player.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/playerPic"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:layout_below="@+id/playerPic"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="104dp"/>
</RelativeLayout>

简单列表项1.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView android:id="@+id/stat_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip"
    android:textSize="16dip"
    android:textStyle="bold"/>

<TextView
    android:id="@+id/stat_number"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip"
    android:textSize="16dip"
    android:textStyle="bold"
    android:layout_below="@id/stat_name"/>


</LinearLayout>

我认为这种行为并不神秘。最后一个设置为
lv
的适配器是幸存的适配器

如果您希望同时添加
statName
statNum
,我会设置其中一个,然后在另一个上使用
.addAll(…)
。例如:

lv = lv.setAdapter(nameAdapter);
lv.addAll(statNum);
nameAdapter.notifyDataSetChanged();

不要忘记最后一行,让您的
列表视图
呈现新数据。

我认为这一行为没有任何错误。最后一个设置为
lv
的适配器仍然存在。那么如何在同一个listview中设置stat_name和stat_num?为您尝试执行的操作添加了答案。