Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - How to display checkbox with specified text at ListActivity?

How to display checkbox with specified text at ListActivity?

Put your problem here if it does not fit any of the other categories.

How to display checkbox with specified text at ListActivity?

Postby Asgard » Sun Dec 23, 2007 9:36 pm

I have some problems:

I created class which extends ListActivity, then I create layout with checkbox description, then I create ArrayAdapter<CheckBox>, which was filled with necessary checkboxes. The problem is that checkboxes displays normal, but instead of my text it shows classname (smth like. android...widget.CheckBox@2832342). I cannot understand where the problem is.

Waiting for you help. :(

Code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MyView extends ListActivity{
  2.  
  3.  
  4.  
  5. ...
  6.  
  7. ArrayAdapter<CheckBox> list = new ArrayAdapter<CheckBox>(this,
  8.  
  9.                            R.layout.checkbox_row, convertToListItem(this.entries));
  10.  
  11.                  
  12.  
  13.                  this.setListAdapter(list);
  14.  
  15. ...
  16.  
  17.  
  18.  
  19.  
  20.  
  21. private List<CheckBox> convertToListItem(List<String> input){
  22.  
  23.                 List<CheckBox> result = new ArrayList<CheckBox>();  
  24.  
  25.                 boxes = new ArrayList<CheckBox>();
  26.  
  27.                 for (String text : input){
  28.  
  29.                         CheckBox temp = new CheckBox(this);
  30.  
  31.                         //temp.append(text);
  32.  
  33.                         temp.setText(text,BufferType.NORMAL);
  34.  
  35.                         //temp.setText("hello");
  36.  
  37.                         result.add(temp);
  38.  
  39.                         boxes.add(temp);
  40.  
  41.                }
  42.  
  43.                 return result;
  44.  
  45.                
  46.  
  47.             }
  48.  
  49.  
  50.  
  51.  
Parsed in 0.024 seconds, using GeSHi 1.0.8.4


Layout:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <CheckBox
  4.  
  5.                 xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.                 android:layout_width="wrap_content"
  8.  
  9.        android:layout_height="wrap_content"
  10.  
  11.        android:textSize="14sp"
  12.  
  13.                 android:typeface="normal"
  14.  
  15.                 android:textStyle="normal"             
  16.  
  17.                 android:layout_weight="0"
  18.  
  19.                 android:layout_gravity="left"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
Catch the moment
Asgard
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Dec 15, 2007 8:49 pm

Top

Postby plusminus » Sun Dec 23, 2007 10:52 pm

Hello Asgard,

your problem is, that your ArrayAdapter<CheckBox> doesn't do the job you are thinking.

Alter your xml-file that it uses a TextView instead:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TextView
  3.          xmlns:android="http://schemas.android.com/apk/res/android"
  4.          android:layout_width="wrap_content"
  5.        android:layout_height="wrap_content"
  6.        android:textSize="16sp"
  7.          android:typeface="normal"
  8.          android:textStyle="normal"        
  9.          android:layout_weight="0"
  10.          android:layout_gravity="left"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

And you will see that there is not even a Exception.
So the conclusion is, that internally just the toString()-method of all the elements in the Adapter is called!

:idea: The solution is just to remain your xml-code as it is and simply use an ArrayAdapter<String> :!:

So an working example:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         List<String> entries = new ArrayList<String>();
  2.         entries.add("Hello");
  3.         entries.add("World");
  4.         entries.add(",");
  5.         entries.add("Hello");
  6.         entries.add("Asgard <img src="http://www.anddev.org/images/smilies/wink.png" alt=";)" title="Wink" />");
  7.         ArrayAdapter<String> list = new ArrayAdapter<String>(this,
  8.                 R.layout.checkbox_row, entries);
  9.  
  10.         this.setListAdapter(list);
Parsed in 0.022 seconds, using GeSHi 1.0.8.4

and it produces the following output:
Image


I think this is what you wanted to do, right :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Asgard » Mon Dec 24, 2007 5:37 pm

Thanks plusminus, it works.

You are really good at Android :)
Catch the moment
Asgard
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sat Dec 15, 2007 8:49 pm

Postby scarydeath » Tue Nov 11, 2008 9:12 pm

When this is done however, how is it possible to tell whether they are pressed?I can't seem to get a isChecked() out of it anywhere.
scarydeath
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 11, 2008 9:06 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests