0

I want nothing but my app to display the strings on the main activity, all that happens when the app opens is the array of strings is displayed. Nothing more nothing less. Can not seem to find this information anywhere!

4
  • How do you want it to look? as a gridView or each string in a new row? What have you tried? Commented Jul 22, 2013 at 20:09
  • Can not seem to find this information anywhere! ? Commented Jul 22, 2013 at 20:13
  • stackoverflow.com/questions/10402428/… Commented Jul 22, 2013 at 20:14
  • You looked? Really? bit.ly/12Zxam6 Commented Jul 22, 2013 at 20:18

3 Answers 3

1

Well, if you wanted to display them in a ListView, use an ArrayAdapter and add the strings to the adapter.

Btw, if the array is in your string resources, use getResources().getStringArray(R.array.id) to get the array from your code.

Sign up to request clarification or add additional context in comments.

Comments

0

Add a textview to the main activity, then make a object of the textview like this.

TextView textView = (TextView) findViewById(R.id.id_of_text_view);

Then set text to the textview like this:

textView.setText("blah");

Get the text from where ever you stored it

Comments

0

You can use ListView component.

list_cars.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="20sp" >
</TextView>


public class ListCarsActivity extends ListActivity {

static final String[] CARS = new String[] { "BWM", "Volvo", "Mersedes-Benz",
        "Honda", "Toyota", "Nexia", "Wolkswagen", "CHevrolet",
        "Ferrari", "Volga", "Porshe", "Bentley", "Bugatti" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //  it is not needed
    // setContentView(R.layout.list_cars);

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_cars,CARS));

    ListView listView = getListView();
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(),
            ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });

}

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.