Multiple Choice List

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Multiple Choice List

Postby darolla » Wed Dec 31, 2008 3:42 pm

Hi,

I'm working on a Multiple Choice List.

1) How do I check some items in Java?
2) How can I change the graphic for the checkbox?

The Activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Wettschein2Activity extends ListActivity {
  3.  
  4.    
  5.  
  6.     private static final String SYSTEM = "system";
  7.  
  8.     private static final String[] PARAM = { SYSTEM };
  9.  
  10.  
  11.  
  12.     private SimpleAdapter adapter;
  13.  
  14.     private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();    
  15.  
  16.  
  17.  
  18.     @Override
  19.  
  20.     public void onCreate(Bundle savedInstanceState) {
  21.  
  22.         super.onCreate(savedInstanceState);
  23.  
  24.         setContentView(R.layout.wettschein2);
  25.  
  26.  
  27.  
  28.         addItem(list, "alle 1er Kombis (+4 Wetten)");
  29.  
  30.         addItem(list, "alle 2er Kombis (+9 Wetten)");
  31.  
  32.         addItem(list, "alle 3er Kombis (+9 Wetten)");
  33.  
  34.         addItem(list, "alle 4er Kombis (+4 Wetten)");
  35.  
  36.         addItem(list, "alle 5er Kombis (+1 Wetten)");
  37.  
  38.        
  39.  
  40.         adapter = new SimpleAdapter(this, list, R.layout.systemwette_list_row, PARAM, new int[] { R.id.systemwette });
  41.  
  42.         setListAdapter(adapter);
  43.  
  44.  
  45.  
  46.         getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  47.  
  48.     }
  49.  
  50.  
  51.  
  52.     public void addItem(List<Map<String, Object>> data, String system) {
  53.  
  54.         Map<String, Object> temp = new HashMap<String, Object>();
  55.  
  56.         temp.put(SYSTEM, system);
  57.  
  58.         data.add(temp);
  59.  
  60.     }    
  61.  
  62. }
  63.  
  64.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The XML for the Activity (shortened):
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
  3.  
  4.        android:layout_height="wrap_content" android:layout_below="@+id/button_ok"
  5.  
  6.        android:scrollbarStyle="outsideInset" android:paddingTop="6dip" />
  7.  
  8.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The XML for every line of the list:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:id="@+id/systemwette" android:layout_width="fill_parent"
  7.  
  8.    android:layout_height="wrap_content"
  9.  
  10.    android:gravity="center_vertical"
  11.  
  12.    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
  13.  
  14.    android:paddingLeft="6dip" android:paddingRight="6dip" />
  15.  
  16.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Happy New Year,
DaRolla
User avatar
darolla
Master Developer
Master Developer
 
Posts: 273
Joined: Thu Sep 25, 2008 5:16 pm
Location: Dortmund, Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests