Skip to content

Using an ArrayAdapter with ListView”

hanisamir79 edited this page Aug 20, 2018 · 1 revision

package com.example.android.trnslate;

import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.GridLayout; import android.widget.GridView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView;

import java.util.ArrayList;

public class NumberActivity extends AppCompatActivity {

ArrayList<String> wordss= new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_number);
    addToArry();

    ArrayAdapter<String> itemAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,wordss);
    ListView listView =findViewById(R.id.listItem);
   // GridView listView = findViewById(R.id.listItem);

    listView.setAdapter(itemAdapter);


}

private void addToArry() {
    wordss.add("one");
    wordss.add("Tow");
    wordss.add("Three");
    wordss.add("Fowr");
    wordss.add("Five");
    wordss.add("Sex");
    wordss.add("Seven");
    wordss.add("Eight");
    wordss.add("nine");
    wordss.add("Ten");

}

}

Finding these guides helpful?

We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.

Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.

Clone this wiki locally