tags:

views:

10

answers:

0

Hello everybody,

i got this wired issue with the SearchDialog.

I followed the tutorial on Using the Android Search Dialog

Everything works fine the search is available from any activity and does his job.

So my problem is that when i invoke the searchactivity with the SearchDialog, my imageorder in the listview, i use, is confused. that means one or more elements in the list have the same image. After a short scroll the listelements have the right image.

When i start the SearchActivity manually by setting the query to a fix value the images have the right order and no element has the same image.(Wihtout using the SearchDialog)

So i think the disorder of my imageviews has to do with the SearchDialog but i don have any idea why this is happening.

Below u find my Adapter and the xml-strukture, which i think are the important parts.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:gravity="center_vertical">
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView android:id="@+id/thumbnail_preview"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:tag="thumb_preview"
            android:minWidth="70dip"
            android:minHeight="70dip"
            android:scaleType="center"
            android:src="@drawable/loading" />
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:orientation="vertical" android:layout_gravity="center_vertical"
            android:paddingTop="22dip">
            <TextView android:id="@+id/name"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_weight="1" android:singleLine="true" android:gravity="left"
                android:paddingLeft="5dip" android:textStyle="bold"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="#FF000000" />
            <TextView android:id="@+id/type"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_weight="1" android:singleLine="true" android:gravity="left"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="normal" android:paddingLeft="5dip" />
        </LinearLayout>
        <ImageView android:id="@+id/button_view"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/ic_btn_round_more_normal" android:adjustViewBounds="true"
            android:layout_gravity="center_vertical"
            android:paddingRight="10dip" />
    </LinearLayout>
</LinearLayout>

And the Adapter.

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

        final Record record = getItem(position);
        ViewHolder holder;

        if (convertView == null)
        {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_view_search, parent, false);
            holder = new ViewHolder();
            holder.imageThumb = (ImageView) convertView.findViewById(R.id.thumbnail_preview);
            holder.imageButton = (ImageView) convertView.findViewById(R.id.button_view);
            holder.text = (TextView) convertView.findViewById(R.id.name);
            holder.type = (TextView) convertView.findViewById(R.id.type);

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

        if (record.isFlag())
        {
            holder.imageButton.setVisibility(ImageView.GONE);
            holder.text.setText(record.hasFirstField().getText());
            holder.text.setVisibility(ImageView.VISIBLE);
            holder.type.setText(record.hasSecondField().getText());
            holder.type.setVisibility(ImageView.VISIBLE);
        }
        else if (!record.isFlag())
        {

            holder.imageButton.setOnClickListener(new OnClickListener()
            {

                public void onClick(View v)
                {
                    Intent intent = new Intent().setClass(getContext(), DetailActivity.class);
                    intent.putExtra("com.objects.record", record); //$NON-NLS-1$
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getContext().startActivity(intent);
                }
            });

            holder.imageButton.setVisibility(ImageView.VISIBLE);
            holder.text.setText(record.hasFirstField().getText());
            holder.type.setVisibility(ImageView.INVISIBLE);
            holder.imageThumb.setImageResource(R.drawable.loading);
            holder.imageThumb.setScaleType(ImageView.ScaleType.CENTER);

            if (!mBusy && !record.isFlag())
            {
                AsyncTask<Record, Void, Drawable> asyncTask = new AsyncDrawableDownloader(getContext(),
                        holder.imageThumb, true, null).execute(record);
                holder.imageThumb.setVisibility(ImageView.VISIBLE);
                holder.imageThumb.setEnabled(false);
            }
            else
            {
                holder.imageThumb.setImageResource(R.drawable.loading);
                holder.imageThumb.setScaleType(ImageView.ScaleType.CENTER);
                holder.imageThumb.setVisibility(ImageView.VISIBLE);
            }
        }
        return convertView;
    }

Hope someone can help me with this.

Here an additional Info the ImageView changes its content. u can watch the imageView change its content, first load is the right image, which is overriden by some other image from the list

Greetings padde83