恶变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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。