亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么ListView 顯示空白??

package?com.example.liusy.myalarm2;

import?android.nfc.Tag;
import?android.support.v7.app.AppCompatActivity;
import?android.os.Bundle;
import?android.util.Log;
import?android.widget.ListView;
import?android.widget.SimpleAdapter;

import?java.util.ArrayList;
import?java.util.HashMap;
import?java.util.List;
import?java.util.Map;

public?class?No2SimpleList?extends?AppCompatActivity?{
????private?static?final?String?TAG?=?"No2SimpleList";
????private?List<Map<String,Object>>?dataList;
????private?SimpleAdapter?simpleAdapter;
????private?ListView?listView;
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_no2_simple_list);
????????listView=(ListView)findViewById(R.id.ListViewSimpleList);
????????dataList=new?ArrayList<Map<String,Object>>();
????????getData();

????????Log.e(TAG,?"is?empty:"+dataList.isEmpty());
????????simpleAdapter?=new?SimpleAdapter(this,dataList,R.layout.support_simple_spinner_dropdown_item,
????????????????new?String[]{"pic","text"},new?int[]{R.id.pic,R.id.text});
????????listView.setAdapter(simpleAdapter);
????????Log.e(TAG,?"simpleAdapter.getItem(1).toString():??"?+simpleAdapter.getItem(1).toString());

????}
????private?List<Map<String,Object>>?getData(){
????????for(int?i=0;i<50;i++){
????????????Map<String,Object>?map?=new?HashMap<String,Object>();
????????????String?text="慕課網"+i;
????????????int?id?=R.drawable.ic_launcher_foreground;
????????????map.put("pic",R.drawable.ic_launcher_foreground);
????????????map.put("text","慕課網"+i);
????????????dataList.add(map);



????????}
????????return?dataList;
????}

}

主界面layout

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

????<ListView
????????android:id="@+id/ListViewSimpleList"
????????android:layout_width="match_parent"
????????android:layout_height="match_parent"></ListView>
</LinearLayout>

列表項layout
<?xml?version="1.0"?encoding="utf-8"?>
<LinearLayout?xmlns:android="http://schemas.android.com/apk/res/android"
????android:orientation="horizontal"
????android:layout_width="match_parent"
????android:layout_height="match_parent">
????<ImageView
????????android:id="@+id/pic"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:layout_marginLeft="15dp"
????????android:src="@drawable/ic_launcher_foreground"
????????/>
????<TextView
????????android:id="@+id/text"
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:textSize="40sp"
????????android:textColor="#609183"
????????android:text="dd"/>

</LinearLayout>


日志輸出

06-20 07:04:47.518 7181-7181/com.example.liusy.myalarm2 E/No2SimpleList: is empty:false

06-20 07:04:47.519 7181-7181/com.example.liusy.myalarm2 E/No2SimpleList: simpleAdapter.getItem(1).toString(): ?{text=慕課網1, pic=2131099733}


正在回答

2 回答

一般可能是,getitemcount的錯誤導致的

0 回復 有任何疑惑可以回復我~
你看下你的R.drawable.ic_launcher_foreground是圖片還是xml文件
0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android攻城獅的第二門課(第1季)
  • 參與學習       111145    人
  • 解答問題       1560    個

本課程由淺入深地帶您學會Android的常用控件的開發和使用

進入課程

為什么ListView 顯示空白??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號