Back to project page SubTweeter.
The source code is released under:
Apache License
If you think the Android project SubTweeter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.henningta.subtweeter; //from w ww .ja va2 s . c o m import java.util.HashSet; import java.util.Set; import twitter4j.ResponseList; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; /** Custom adapter with options to select/highlight index */ public class StatusAdapter extends ArrayAdapter<twitter4j.Status> { private LayoutInflater inflater; private int resourceId; private HashSet<twitter4j.Status> checkedItems; private boolean multiMode; public StatusAdapter(Context context, int resourceId, ResponseList<twitter4j.Status> objects) { super(context, resourceId, objects); this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.resourceId = resourceId; this.checkedItems = new HashSet<twitter4j.Status>(); this.multiMode = false; } @Override public View getView(int position, View convertView, ViewGroup parent) { ItemHolder holder = null; if (convertView == null) { // create new holder = new ItemHolder(); convertView = inflater.inflate(resourceId, null); holder.name = (TextView)convertView.findViewById(R.id.status_name); holder.screenName = (TextView)convertView.findViewById(R.id.status_screenname); holder.text = (TextView)convertView.findViewById(R.id.status_text); convertView.setTag(holder); } else { // recycle holder = (ItemHolder)convertView.getTag(); } twitter4j.Status status = this.getItem(position); holder.name.setText(status.getUser().getName()); holder.screenName.setText("@" + status.getUser().getScreenName()); holder.text.setText(status.getText()); /* set default styles */ //convertView.setBackgroundResource(R.drawable.event_selector_default); /* set checked state */ /*if (checkedItems.contains(status)) { // if this item is checked convertView.getBackground().setState(new int[] { android.R.attr.state_checked }); } else { // if this item is unchecked (notice the minus) convertView.getBackground().setState(new int[] { -android.R.attr.state_checked }); }*/ return convertView; } class ItemHolder { TextView name; TextView screenName; TextView text; } /** Begin multi-mode selection of items */ public void enterMultiMode() { multiMode = true; notifyDataSetChanged(); } /** Stop selecting items */ public void exitMultiMode() { checkedItems.clear(); multiMode = false; notifyDataSetChanged(); } /** Set item at current position to checked or unchecked */ public void setChecked(int position, boolean checked) { twitter4j.Status status = this.getItem(position); if (checked) checkedItems.add(status); else checkedItems.remove(status); if (multiMode) notifyDataSetChanged(); } /** Return checked state of item at position */ public boolean isChecked(int position) { return checkedItems.contains(this.getItem(position)); } /** Toggle checked state of item at position */ public void toggleChecked(int position) { final twitter4j.Status status = this.getItem(position); if (checkedItems.contains(status)) checkedItems.remove(status); else checkedItems.add(status); notifyDataSetChanged(); } /** Return number of checked items */ public int getCheckedItemCount() { return checkedItems.size(); } /** Return set of checked items */ public Set<twitter4j.Status> getCheckedItems() { return checkedItems; } }