-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Using an ArrayAdapter with ListView”
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");
}
}
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
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.