Hi
I have a Activity that uses an array adapter to show 4 lists each under a
tab (as in the code below). Each item in the list is a CheckedTextView as in
the layout file at the bottom. How do i set individual items "checked" in
one of those lists?
Thanks in advance.
public class TagPicker extends TabActivity {
TabHost mTabHost;
StoreListAdaptor allListAdaptor, analogListAdaptor, digitalListAdaptor,
stringListAdaptor, eventListAdaptor;
ListView listViewAll, listViewAnalog,listViewDigital , listViewString,
listViewEvent;
SmartList smartTagList;
ListOfActiveTags listOfActiveTags;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tagpickerlayout);
smartTagList = SmartList.getInstance();
listOfActiveTags = ListOfActiveTags.getInstance();
mTabHost = getTabHost();
Resources res = getResources();
mTabHost.addTab(mTabHost.newTabSpec("allTab").setIndicator("All",res.getDrawable(R.drawable.ic_menu_tags)).setContent(R.id.alllist));
mTabHost.addTab(mTabHost.newTabSpec("analogueTab").setIndicator("Analogue",res.getDrawable(R.drawable.ic_menu_clock)).setContent(R.id.alist));
mTabHost.addTab(mTabHost.newTabSpec("discreteTab").setIndicator("Discrete",res.getDrawable(R.drawable.ic_menu_light)).setContent(R.id.dlist));
mTabHost.addTab(mTabHost.newTabSpec("stringTab").setIndicator("String",res.getDrawable(R.drawable.ic_menu_tags)).setContent(R.id.slist));
mTabHost.addTab(mTabHost.newTabSpec("eventTab").setIndicator("Event",res.getDrawable(R.drawable.ic_menu_flash)).setContent(R.id.elist));
mTabHost.setCurrentTab(0);
listViewAll = (ListView) findViewById(R.id.alllist);
listViewAll.setItemsCanFocus(false);
listViewAll.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listViewAll.setFastScrollEnabled(true);
listViewAnalog = (ListView) findViewById(R.id.alist);
listViewAnalog.setItemsCanFocus(false);
listViewAnalog.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listViewAnalog.setFastScrollEnabled(true);
listViewDigital = (ListView) findViewById(R.id.dlist);
listViewDigital.setItemsCanFocus(false);
listViewDigital.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listViewDigital.setFastScrollEnabled(true);
listViewString = (ListView) findViewById(R.id.slist);
listViewString.setItemsCanFocus(false);
listViewString.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listViewString.setFastScrollEnabled(true);
listViewEvent = (ListView) findViewById(R.id.elist);
listViewEvent.setItemsCanFocus(false);
listViewEvent.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listViewEvent.setFastScrollEnabled(true);
listViewEvent.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView,
int myItemInt, long mylng) {
boolean checked = listViewEvent.isItemChecked(myItemInt);
Object t = (listViewEvent.getItemAtPosition(myItemInt));
if(checked){listOfActiveTags.add((Tag) t);}
else
{listOfActiveTags.remove((Tag) t);}
}
});
if(smartTagList != null)
{
allListAdaptor = new StoreListAdaptor(this,smartTagList.subList(0,
PlantPulseActivity.lastEtag));
listViewAll.setAdapter(allListAdaptor);
analogListAdaptor = new StoreListAdaptor(this,smartTagList.subList(0,
PlantPulseActivity.lastAtag));
listViewAnalog.setAdapter(analogListAdaptor);
digitalListAdaptor = new
StoreListAdaptor(this,smartTagList.subList(PlantPulseActivity.lastAtag,PlantPulseActivity.lastDtag));
listViewDigital.setAdapter(digitalListAdaptor);
stringListAdaptor = new
StoreListAdaptor(this,smartTagList.subList(PlantPulseActivity.lastDtag,PlantPulseActivity.lastStag));
listViewString.setAdapter(stringListAdaptor);
eventListAdaptor = new
StoreListAdaptor(this,smartTagList.subList(PlantPulseActivity.lastStag,
PlantPulseActivity.lastEtag));
listViewEvent.setAdapter(eventListAdaptor);
}
final Button okButton = (Button) findViewById(R.id.taglistOK);
okButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TagPicker.this.finish();
}
});
final Button button = (Button) findViewById(R.id.taglistCancel);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TagPicker.this.finish();
}
});
}
class StoreListAdaptor extends ArrayAdapter<Tag> implements SectionIndexer{
HashMap<String, Integer> alphaIndexer;
String[] sections;
private List<Tag> items;
public StoreListAdaptor(Context context, List<Tag> list) {
super(context, R.layout.listitem, list);
this.items = list;
alphaIndexer = new HashMap<String, Integer>();
int size = list.size();
for (int x = 0; x < size; x++) {
String s = list.get(x).getName();
//listOfActiveTags.contains(list.get(x));
// get the first letter of the store
String ch = s.substring(0, 1);
// convert to uppercase otherwise lowercase a -z will be sorted after upper
A-Z
ch = ch.toUpperCase();
// HashMap will prevent duplicates
alphaIndexer.put(ch, x);
}
Set<String> sectionLetters = alphaIndexer.keySet();
// create a list from the set to sort
ArrayList<String> sectionList = new
ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
public int getPositionForSection(int section) {
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position) {
return 1;
}
public Object[] getSections() {
return sections;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
android:id="@android:id/text1"/>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en