views:

42

answers:

2

Still new to Android

I want to display some data as an HTML-like ordered list (non-actionable).

Example;

  1. Item One
  2. Item Two
  3. Item Three

I feel I am missing something obvious.

Thanks, JD

A: 

Either use a ListView and do nothing when something is selected, Use an AlertDialog.Builder and call setItems and do nothing in the Select handler, or use a WebView and create the list in html as on ordered list.

BrennaSoft
Thanks, WebView looks interesting, problem being (as far as I can tell) is that the list we want to display is going to be different each time- its a search display results interface. Good to know about WebView though - that was new for me.
A: 

There's no default view or widget to do this i guess. You can try with ListView or doing the views programatically (however this is a little dirty)

The xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llMain"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

</LinearLayout>

The Activity:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //Get your main layout from the XML
        LinearLayout llMain = (LinearLayout) findViewById(R.id.llMain);

        ArrayList<String> alItems = new ArrayList<String>();
        //Put some example data
        alItems.add("Text1");
        alItems.add("Text2");
        alItems.add("Text3");

        for(int i=0; i<alItems.size(); i++){
            //We create a Layout for every item
            LinearLayout ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.HORIZONTAL);

            //A TextView to put the order (ie: 1.)
            TextView tv1 = new TextView(this);
            tv1.setText(i+1 + ". ");

            ll.addView(tv1, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0));

            //TextView to put the value from the ArrayList
            TextView tv2 = new TextView(this);
            tv2.setText(alItems.get(i));

            ll.addView(tv2, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));

            //Add this layout to the main layout of the XML
            llMain.addView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0));
        }
    }
YaW
Thanks, this very similar to the 'dirty' solution I came up with myself..and I agree - it's messy