MADDY
MADDY

Reputation: 147

how to show only two rows of data in the listview of android

i am getting problem as i have some data in a database tabel file i am successfully able to show data into it but .as the data is going bigger the list view item data is also increasing .in need to show only 2 lines of data into it so that all the data i can show sufficiently .

This is the image of the list view enter image description here

Please help me achieving this . this is the code i am writing in main Activity class

        ArrayList<String> results = myDbHelper.getNamesArray(MY_DATABASE_TABLE); 
        //setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, COUNTRIES));
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, results));
        this.setTitleColor(Color.BLACK);
        ListView lv=(ListView)findViewById(android.R.id.list);
        lv.setCacheColorHint(0);
        lv.setTextFilterEnabled(true);

Thanks in advance. Moqthar.

Upvotes: 1

Views: 1281

Answers (2)

Daan Geurts
Daan Geurts

Reputation: 449

You need to make a custom row view with a TextView in it. Here you can set your TextView to 2 lines with android:lines

Upvotes: 1

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43088

You need to use custom layout for your listview item. Take TextView and make advantage of ellipsize and singleLine properties.And Use android:maxLines=2 in textview...

Upvotes: 3

Related Questions