如何将数组值放入hashmap并显示?

时间:2017-02-17 20:03:40

标签: android arrays hashmap

如何将数组值放入hashmap?

这是我的代码:

public class ListShowActivity extends AppCompatActivity {

TextView textView;
DataBase dataBase;
String [] TR_WORDS;
String [] EN_WORDS;

private ArrayList<HashMap<String, String>> list;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_show);
    ListView listView=(ListView)findViewById(R.id.listShowMain);
    dataBase = new DataBase(getApplicationContext());

    ArrayList<Words> enWordlist  = (ArrayList<Words>) dataBase.allEnWords();
    ArrayList<Words> trWordlist  =(ArrayList<Words>) dataBase.allTrWords();

    TR_WORDS = new String[trWordlist.size()];
    EN_WORDS = new String[enWordlist.size()];

    for(int i=0;i<enWordlist.size();i++){
        EN_WORDS[i] =enWordlist.get(i).getWORD().toString();
        TR_WORDS[i] =trWordlist.get(i).getTR1().toString();
    }

    list=new ArrayList<HashMap<String,String>>();

    HashMap<String,String>  temp = new HashMap<String, String>();

    for(int j=0;j<=3;j++){
        temp.put(FIRST_COLUMN,""+j);
        temp.put(SECOND_COLUMN, EN_WORDS[j]);
        temp.put(THIRD_COLUMN, TR_WORDS[j]);

        list.add(temp);
    }



    ListViewAdapters adapter=new ListViewAdapters(this, list);
    listView.setAdapter(adapter);

我想把数组放在hashmap中。

喜欢;

温度[J]。把(FIRST_COLUMN “” + j)的

温度[J]。把(是second_column,TR_WORDS [J])

温度[J]。把(THIRD_COLUMN,EN_WORDS [J])

list.add(温度[J])

我该怎么做?

0 个答案:

没有答案