恶变133 2015-09-17 00:53 采纳率: 33.3%
浏览 1885

数据已经从数据库返回结果,却没在窗口显示出来,大神帮我看一下.

这是在MainActivity的显示方法

 public class MainActivity extends AppCompatActivity {
    private  ListView listView;
    private PersonService personService;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        personService = new PersonService(this);
        listView = (ListView) findViewById(R.id.listView);
        show();
        }

    private void show() {
        List<Person> personList = personService.getScrollDate(1, 20);
        List<HashMap<String,Object>> data= new ArrayList<HashMap<String, Object>>();
        HashMap<String,Object> item;
        for(Person person:personList)
        {
            item = new HashMap<String,Object>();
            item.put("id",person.getId());
            item.put("name",person.getName());
            item.put("phone", person.getPhone());
            data.add(item);
        }
        //适配器用来实现数据与条目,条目与listView的绑定。
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,data,R.layout.item,new String[]{"id","name","phone"},new int[]{R.id.id,R.id.name,R.id.phone});
        listView.setAdapter(simpleAdapter);
    }

这是item.xml内容

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    >

    <TextView
        android:layout_width="150dip"
        android:layout_height="wrap_content"
        android:id="@+id/id"
        />
    <TextView
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:id="@+id/name"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/phone"
        />
</LinearLayout>

这是activity_main.xml内容

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
  >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >

        <TextView
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:text="@string/id"
            />
        <TextView
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:text="@string/name"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/phone"
            />


    </LinearLayout>
<ListView
    android:background="#ff0000"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    />

</LinearLayout>

  • 写回答

6条回答 默认 最新

  • _H_JY 2015-09-17 01:21
    关注

    先打印data出来看看有没有数据,我猜你没成功获取数据

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了