如何在Arraylist项中获取对象的值?

时间:2016-02-25 08:01:48

标签: android object arraylist

在我通过循环显示值之后,我得到了一些array-list的结果

routerApp.directive('btnAttrClick', function() {
  return {
    controller: 'simulate',
    link: function(scope, element, attr) {
      element.on('click', function() {
        scope.nip = attr.id;
      })
    }
  }
})

我得到的结果来自:

<div class="modal-overlay fade">
  <div class="modal-content">
  <h2>Modal</h2>
  This modal has a substate.  <a ui-sref=".substate">{{nip}}</a>
  <div ui-view='modal'></div>
  <a ui-sref="app">{{nip}}</a>
  </div>
</div>

我从:

创建了这个arraylist
{First=00157300-SPT R.ALONSO (M) D.GREEN, Fourth=360010.0, Second=10, Third=360000}

我从Constant.java创建了FIRST_COLUMN,SECOND_COLUMN,THIRD_COLUMN和FOURTH_COLUMN:

for(int i = 0; i<list.size(); i++){
   Log.d("List Result :", String.valueOf(list.get(i)));
}

我使用import到MainActivity.java:

HashMap temp = new HashMap();

temp.put(FIRST_COLUMN, valueSpinner);
temp.put(SECOND_COLUMN, count);
temp.put(THIRD_COLUMN, price);
temp.put(FOURTH_COLUMN, total);

list.add(temp);

如何才能获得public class Constant { public static final String FIRST_COLUMN = "First"; public static final String SECOND_COLUMN = "Second"; public static final String THIRD_COLUMN = "Third"; public static final String FOURTH_COLUMN = "Fourth"; } import static com.testing.informationsystem.Constant.FIRST_COLUMN; import static com.testing.informationsystem.Constant.SECOND_COLUMN; import static com.testing.informationsystem.Constant.THIRD_COLUMN; import static com.testing.informationsystem.Constant.FOURTH_COLUMN;

谢谢。

1 个答案:

答案 0 :(得分:0)

好像您在列表中添加了Map,因此您最终打印了Map的toString方法。可能没有必要在这样的列表中使用Map,但我认为它应该是。你想要做的是从地图请求键值对,而不是使用toString方法。

for(int i = 0; i < list.size(); i++)
{
   HashMap temp = list.get(i);
   Log.d("List Result :", "index " + i);
   Log.d("List Result :", "First = " + temp.get(FIRST_COLUMN));
   Log.d("List Result :", "Second = " + temp.get(SECOND_COLUMN));
   Log.d("List Result :", "Third= " + temp.get(THIRD_COLUMN));
   Log.d("List Result :", "Forth= " + temp.get(FOURTH_COLUMN));
}