恶变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出来看看有没有数据,我猜你没成功获取数据

    评论

报告相同问题?

悬赏问题

  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案