Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_list_item_2 in Android

after creating some menus with simple_list_item_1 (which worked very fine) I tried to replace this by simple_list_item_2, but my system throws around with exceptions...

Now I'm wondering how to create such a two-different-sized-line-entry for my list...is there any trap for beginners? Can someone please help me fixing my (small!?) problem?

My code looks like this:

ListAdapter listAdapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_2, fileNames);
setListAdapter(listAdapter);

My String[] fileNames stores all strings to display in ascending order (does this matter for the functionality?!)

After unsuccessfully searching in some forums I now hope that someone of you can give me an useful suggestion.

nice greetings, poeschlorn

like image 326
poeschlorn Avatar asked Jun 08 '10 07:06

poeschlorn


People also ask

What is the use of R ID in android?

R. id. text1 is an used for TextView views. You can find it in many layouts from the framework ( select_dialog_item , select_dialog_singlechoice , simple_dropdown_item_1line , etc.).

What is the purpose of using setContentView R layout Activity_main )?

What is the purpose of using setContentView R layout Activity_main )? layout. activity_main ); This is a Java method called setContentView. It sets the XML file you want as your main layout when the app starts.

What is simple_list_item_1?

android.R.layout.simple_list_item_1 , this is row layout file in your res/layout folder which contains the corresponding design for your row in listview .

What is Simple_spinner_item?

simple_spinner_item is the layout of each drop-down item on the spinner list.


1 Answers

simple_list_item_2 is different, instead of just a TextView it contains a TwoLineListItem containing two TextViews. ArrayAdapter is not going to work here, because the constructor you're using expects only a TextView; just look at the constructors. Instead you'll either have to create a custom adapter or use one that supports it like SimpleCursorAdapter or (I think) SimpleAdapter. This guy has a somewhat hacky solution that might work for you.

like image 197
Daniel Waechter Avatar answered Nov 15 '22 13:11

Daniel Waechter