如何使用Map <string,object =“”>设置文本?

时间:2016-04-30 18:45:57

标签: java android listview kumulos

原始邮件:

如何使用对象设置textview?我从Web服务数据库中提取数据并将其设置为对象。然后我尝试将对象中的数据设置为textview。

我需要帮助:

1)使用Map String,Object

设置textview

关于网络服务数据库的上一篇文章:Populating a ListView with Kumulos?

更新代码:

对象:

static class Person{

    public long personID;
    public String lastName;
    public String middleName;
    public String firstName;
    public String dateOfBirth;
    public String personAddress;
    public int phoneNumber;
    public int driversLicense;
    public int socialSecurity;
    public String personRace;
    public String personSex;
    public String personAge;

    public static Person createFromGenericMap(Map<String, Object> object) {

        Person p = new Person();

        p.personID = Long.valueOf(object.get("personID").toString());
        p.lastName = (String) object.get("lastName");
        p.middleName = (String) object.get("middleName");
        p.firstName = (String) object.get("firstName");
        p.dateOfBirth = (String) object.get("dob");
        p.personAddress = (String) object.get("address");
        p.phoneNumber = Integer.valueOf(object.get("phone").toString());
        p.driversLicense = Integer.valueOf(object.get("dl").toString());
        p.socialSecurity = Integer.valueOf(object.get("ss").toString());
        p.personRace = (String) object.get("race");
        p.personSex = (String) object.get("sex");
        p.personAge = (String) object.get("age");

        return p;
    }
}

我的适配器:

static class PersonAdapter extends BaseAdapter {

    private List<Person> people;
    private static LayoutInflater inflater = null;

    public PersonAdapter(Context context, List<Person> people){
        this.people = people;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    @Override
    public int getCount() {
        return people.size();
    }

    @Override
    public Object getItem(int position) {
        return people.get(position);
    }

    @Override
    public long getItemId(int position) {
        Person p = people.get(position);
        return p.personID;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = convertView;

        LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {

            view = inflater.inflate(R.layout.personlist_row, null);

            TextView dl = (TextView) view.findViewById(R.id.tvdl);
            TextView last = (TextView) view.findViewById(R.id.tvLastName);
            TextView first = (TextView) view.findViewById(R.id.tvFirstName);
            TextView middle = (TextView) view.findViewById(R.id.tvMiddleName);
            TextView ss = (TextView) view.findViewById(R.id.tvSS);

            Person mperson = people.get(position);

            dl.setText(mperson.driversLicense);
            last.setText(mperson.lastName);
            first.setText(mperson.firstName);
            middle.setText(mperson.middleName);
            ss.setText(mperson.socialSecurity);   
        }

ERROR:

  

05-09 23:34:02.000 2418-2418 / com.f0xcr4f7.intelwatch E / AndroidRuntime:   致命异常:主要过程:com.f0xcr4f7.intelwatch,PID:2418   android.content.res.Resources $ NotFoundException:字符串资源ID   &#39;#0x2d9f9219在android.content.res.Resources.getText(Resources.java:299)at   android.widget.TextView.setText(TextView.java:4132)at   com.f0xcr4f7.intelwatch.PersonSearchPop $ PersonAdapter.getView(PersonSearchPop.java:112)

1 个答案:

答案 0 :(得分:1)

至于我,这部分看起来很奇怪。

var app = angular.module('app', []);

app.factory('MyService', ['$http',function($http) {
    return {
       getData: function() {
          return $http.get('/api/endpoint');
       }
    };
}]);

app.controller('MyController', ['$scope', '$http', 'MyService', function($scope, $http, MyService){
   MyService.getData().then(function(response){
     $scope.myVarialbe = response.data;
   });
}]);

您将mperson定义为HashMap,但是您从人员处接收Person对象,即Person of List。 所以我会做什么

   --------------------------------------------------------------------
        Map<String, Object> mperson = new HashMap<String, Object>();
        mperson = people.get(position);

        dl.setText(mperson.getString("dl"));
    --------------------------------------------------------------------