从数组中的特定字段填充

时间:2017-06-02 11:18:52

标签: java android arrays populate

我试图将数据从数组中检索到文本字段,这是一个列表视图,现在我有了这个

txtDesignacao.setText(position + 1 + todasAsCategorias.toString());

它的工作:

enter image description here

问题是,我只想要" Designacao"领域,在这种情况下将是" Azeites& Outros",我怎样才能做到这一点?

##########################编辑

TodasAsCategorias.class:

@Override
    protected Void doInBackground(Void... params) {
        HttpHandler sh = new HttpHandler();
        String url1 = "something";
        String url2 = "something2";

        for (int idCat = 0; idCat <100; idCat++){
            final String jsonStr = sh.makeServiceCall(url1 + idCat + url2);
            if (jsonStr != null) {
                try {
                    JSONObject jsonObject = new JSONObject(jsonStr);
                    String K_PRODUTO = jsonObject.getString("K_PRODUTO");
                    String Designacao = jsonObject.getString("Designacao");
                    HashMap<String, String> cat = new HashMap<>();
                    cat.put("K_PRODUTO", K_PRODUTO);
                    cat.put("Designacao", Designacao);
                    listaCategorias.add(cat);
                } catch (final JSONException e) {
                    //DO SOMETHING
                }
            } else {
                //DO SOMETHING
            }
        }
        return null;
    }

@Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        mAdapter = new ListViewAdapter(mContext);
        lv.setAdapter(mAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //Do Something
            }
        });
    }
}

public static ArrayList<HashMap<String, String>> getListaCategorias() {
    return listaCategorias;
}

ListViewAdapter.class:

@Override
public void fillValues(int position, View convertView) {
    ArrayList array = TodasAsCategorias.getListaCategorias();
    Object todasAsCategorias = array.get(i);
    TextView txtDesignacao = (TextView) convertView.findViewById(R.id.Designacao);
    txtDesignacao.setText(position + 1 + todasAsCategorias.toString());
}

1 个答案:

答案 0 :(得分:1)

你有一个todasAsCategorias作为对象。只是todastAsCate.Designacao,如果它是公共财产,或todastAsCate.getDesignacao()。您所要做的就是检查你的todasAsCategorias对象