My getView() method in the class ListViewAdapter....

public View getView(int position, View convertView, ViewGroup parent)
{

            Log.i(myLog, "In the getView() method");
            ViewHolder holder;
            if(convertView == null){

                   convertView = mInflater.inflate(R.layout.list_view,
null);
                   holder = new ViewHolder();
                   holder.text = (TextView) convertView
                     .findViewById(R.id.TextView01);

                   int tvWidth = width / 3;

                   holder.text.getLayoutParams().width = tvWidth;
                   holder.text.getLayoutParams().height = (height /
6);
                    holder.text2 = (TextView) convertView
                    .findViewById(R.id.TextView02);
                    holder.text2.getLayoutParams().width = tvWidth;
                    holder.text2.getLayoutParams().height = (height /
6);
                    holder.text3 = (TextView) convertView
                    .findViewById( R.id.TextView03);
                    holder.text3.getLayoutParams().width = tvWidth;
                    holder.text3.getLayoutParams().height = (height /
6);
                        //convertView.setBackgrsetoundColor((position
% 2) == 0 ? Color.parseColor("#DEE8F1") : Color.LTGRAY);
                    convertView.setBackgroundColor(Color.WHITE);

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

                }

                holder.text.setGravity(position == 0 ?
Gravity.CENTER : Gravity.LEFT);
                holder.text2.setGravity(Gravity.CENTER);
                holder.text3.setGravity(Gravity.CENTER);
                if(position == 0){
                    Log.i(myLog, "========" + position + "=========");
                    holder.text.setBackgroundColor(Color.GRAY);
                    holder.text2.setBackgroundColor(Color.GRAY);
                    holder.text3.setBackgroundColor(Color.GRAY);

                    holder.text.setTextColor(Color.WHITE);
                    holder.text2.setTextColor(Color.WHITE);
                    holder.text3.setTextColor(Color.WHITE);
                    holder.text.setText( Html.fromHtml("<b> SCRIP</
b>") );
                    holder.text2.setText( Html.fromHtml("<b>ClOSE</
b>" ) );
                    holder.text3.setText( Html.fromHtml("<b>CHG%</
b>" ) );

                }else{

                    holder.text.setText( Html.fromHtml("<b>" +
scripVector.elementAt( position - 1).toString() + "</b>") );
                    holder.text2.setText( Html.fromHtml("<b>" +
closeVector.elementAt(position - 1).toString() + "</b>" ) );

                    if(change[position - 1].indexOf("-") > -1){
                        holder.text3.setBackgroundColor(Color.RED);
                        holder.text3.setText( Html.fromHtml("<b>" +
changeVector.elementAt(position - 1).toString() + "</b>" ) );
                    }else{
                        holder.text3.setTextColor(Color.GREEN);
                        holder.text3.setText( Html.fromHtml("<b>" +
changeVector.elementAt(position - 1).toString() + "</b>" ) );
                    }
                }


                return convertView;
    }

The above is my getView(...) method...

On Long press of the item, i show an AlertDialog which allows the user
to add, delete,edit, removeAll a row...

Now the value of the each of the TextViews (total 3) which I have
inflated into the ListView is associated with 3 different Vector
elements respectively..

I longclick on position 2, alert dialog pops up, I set delete
operation at row 2 and then I set the an empty string at each of the
vectors at the same location (i.e at 2), and then i call a method
updateList();

public boolean onItemLongClick( AdapterView<?> parent, View arg1, int
position, long arg3) {

                final int k = position;
                final View view = arg1;
                final AdapterView aView = parent;
                 Toast.makeText(ctx, "position: " + k,
                        Toast.LENGTH_SHORT).show();
                if(position > 0){
                    final CharSequence[] items = {"Add scrip", "Delete
scrip", "Move scrip"};

                    AlertDialog.Builder builder = new
AlertDialog.Builder(ctx);
                    builder.setTitle("Group Action");
                    builder.setItems(items, new
DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
int item) {

                            Toast.makeText(ctx, items[item],
Toast.LENGTH_SHORT).show();

                            Log.i(myLog, "" + scripVector.size() + "
" + aView.getChildCount());

                            updateList(k); // this method changes the
Vector elements.....

                        }

                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                }

                return true;
    }

public void updateList(){
     this.notifyDataSetChanged();
    //what I understood from the documentation at
developer.android.com, this method should refresh the list
automatically....
    //It does it, but it changes the last row of the list surprisingly
and applies it the look which I have set for the 1st row in the
getView(...) method...
    //Or may be, i am committing a minor mistake.
}




On Mar 3, 8:51 pm, Justin Anderson <[email protected]> wrote:
> Can you post your entire getView method?
> On Mar 3, 2011 11:46 AM, "NR" <[email protected]> wrote:
>
> > Any suggestions how to solve it... i simply call the
> > notifyDataSetChanged() method in my CustomBaseAdapter class....
>
> > Do I have to set the adapter again to the listview? like
> > ListView.setAdapter(adapter)
>
> > On Mar 3, 3:59 pm, Justin Anderson <[email protected]> wrote:
> >> This sounds like it could be a view recycling issue
> >> On Mar 3, 2011 3:42 AM, "Namit Rana" <[email protected]> wrote:
>
> >> > I have a ListView with a custom BaseAdapter.
>
> >> > in getView(...) in CustomBaseAdapter class...
>
> >> > I have specified gray color in the 1st row and white color in all
> >> > other rows.
>
> >> > if(position==0){
> >> > holder.text1.setBackGroundColor(Color.gray) // same for next 2
> >> > TextView views.
> >> > }else{
> >> > //set the textview color to white
> >> > }
>
> >> > After I change the content of the specific row (all textViews), I
> >> > call
> >> > this.notifyDataSetChanged();
>
> >> > The data gets updated properly, but the last row of the ListView
> >> > displays gray color along with the first row.
> >> > But I have set the gray color to the 1st row..
>
> >> > Any help???
> >> > Regards
>
> >> > --
> >> > 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
>
> > --
> > 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
>
>

-- 
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

Reply via email to