GridView - setting selection to last item also loads first item

by Mark Murphy » Mon, 19 Jul 2010 22:54:36 GMT


Sponsored Links
 


setTag() is 1.0+. Indexed setTag() is 1.6+.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--



Other Threads

1. Custom ListView with ItemClick listener & notifyDataSetChanged

Hello,
I tried to have a customed listview with the itemclick listener. I
followed with some small modifications the tutorials from
http://www.androidpeople.com/android-custom-listview-tutorial-example/.
If I put in comment "adapter.notifyDataSetChanged();", all work well:
when I click on an item, the listener is fired. But if I use
"adapter.notifyDataSetChanged();" (I need it because my list will be
constructed dynamically), no listener is fired when I click on any
item.
Does someone have an idea about the error I made ? Or shall I use
another way to do what I want ?

Thanks !

Here are my codes:
public class CustomListViewOnClick extends Activity {
        private CustomListView l1;


        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                l1 = new CustomListView(this);
                setContentView(l1);
        }
}

public class CustomListView extends ListView {
        private static Context context;
        private EfficientAdapter adapter;

        private class EfficientAdapter extends BaseAdapter {
                private LayoutInflater mInflater;

                public EfficientAdapter(Context context, int 
textViewResourceId) {
                        mInflater = LayoutInflater.from(context);

                }

                public int getCount() {
                        return country.length;
                }

                public Object getItem(int position) {
                        return position;
                }

                public long getItemId(int position) {
                        return position;
                }

                public View getView(int position, View convertView, ViewGroup
parent) {
                        ViewHolder holder;
                        if (convertView == null) {
                                convertView = 
mInflater.inflate(R.layout.listview, null);
                                holder = new ViewHolder();
                                holder.text = (TextView) convertView
                                                .findViewById(R.id.TextView01);
                                holder.text2 = (TextView) convertView
                                                .findViewById(R.id.TextView02);

                                convertView.setTag(holder);
                        } else {
                                holder = (ViewHolder) convertView.getTag();
                        }

                        holder.text.setText(curr[position]);
                        holder.text2.setText(country[position]);

                        return convertView;
                }

                class ViewHolder {
                        TextView text;
                        TextView text2;
                }
        }

        public CustomListView(Context context) {
                super(context);
                CustomListView.context = context;
                adapter = new EfficientAdapter(context, R.layout.listview);
                setAdapter(adapter);
                setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> a, View v, int 
position,
                                        long id) {
                                AlertDialog.Builder adb;
                                adb = new 
AlertDialog.Builder(CustomListView.context);
                                adb.setTitle("LVSelectedItemExample");
                                adb.setMessage("Selected Item is = "
                                                + getItemAtPosition(position));
                                adb.setPositiveButton("Ok", null);
                                adb.show();
                        }
                });
        }

        @Override
        protected void onDraw(Canvas canvas) {
                adapter.notifyDataSetChanged();
        }

        private static final String[] country = { "Iceland", "India",
"Indonesia",
                        "Iran", "Iraq", "Ireland", "Israel", "Italy", "Laos", 
"Latvia",
                        "Lebanon", "Lesotho ", "Liberia", "Libya", "Lithuania",
                        "Luxembourg" };
        private static final String[] curr = { "ISK", "INR", "IDR", "IRR",
"IQD",
                        "EUR", "ILS", "EUR", "LAK", "LVL", "LBP", "LSL ", 
"LRD", "LYD",
                        "LTL ", "EUR"

        };

-- 

2. Is there an Android view/layout/widget that allows flinging/swiping between included views?

I'm looking for a layout that includes different views and allows
switching between them, but unlike the tab view which switches
instantly and uses a large amount of screen real estate, allows the
user to fling/swipe between the views (ideally with small images
indicating how many views are available and which one is the current
one like, forgive me, iPhone apps display).

The HorizontalScrollView view allows flinging, but does not have a
separation between screens.

If there isn't a standard component that does this, is there another
that is often used for this purpose?

I realize I could implement this myself without too much trouble using
gestures, but I'd like to avoid reinventing the wheel (if, that is,
it's already been invented in this case) and defining my own
thresholds for the fling action means my app and other apps that try
to do the same thing do not provide a consistent user experience.



-- 

3. Restlet api

4. Ym bermasalah

5. adb causing 100% cpu usage

6. Tegra 2 / GTablet does not expose reqGlEsVersion correctly...

7. Google Checkout Change - delayed bulk payments.