简体   繁体   中英

update horizontal scroll-view inside Android listview

I,m developing an application of horizontalListView inside ListView from SQlite.When i scroll down ListView my horizontallistview will be increasing with double entry.I have tried with adapter.notifyDataSetChanged(); ,but it not effect on horizontalListView.Any thoughts on how i should go about doing this.

List<All_Post> allDesc = dbhelper.getAllDescriptions();
            for (All_Post all_Post : allDesc)
            {
                descArray.add(all_Post);
            }

            final MyListAdapter adapter = new MyListAdapter(this, R.layout.all_post_row, descArray);
            listView.setAdapter(adapter);
            adapter.notifyDataSetChanged();

 listView.setOnDetectScrollListener(new OnDetectScrollListener() {
            @Override
            public void onUpScrolling() {
        /* do something */

                adapter.notifyDataSetChanged();
                Log.e("onUpScrolling ", "!!!!!!");
            }

            @Override
            public void onDownScrolling() {
        /* do something */
                adapter.notifyDataSetChanged();
                Log.e("onDownScrolling ", "!!!!!!");
            }
        });

Here is my Adapter getView() method with HorizontalListView

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        Holder holder = null;
        if (row == null) 
        {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            row = vi.inflate(R.layout.all_post_row, null);
            holder = new Holder();
            holder.horizontalScrollView = (HorizontalScrollView)row.findViewById(R.id.hlist);
            row.setTag(holder);
        }
        else
        {
            holder = (Holder) row.getTag();
        }

        dbhelper = new MyDbHelper(AllPosts_Page.this);
        SQLiteDatabase db = dbhelper.getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from ActivityObjectList where activityId " + "= ? ", new String[]{strDescription});
        ArrayList<String> imageArray = new ArrayList<String>();
        if (cursor.moveToFirst())
        {
            do
            {
                String imagePath = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
                Log.e("imagePath "," = " + imagePath);
                String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
                String path = baseDir + "/SDImages/" + imagePath;

                imageArray.add(path);
            }
            while (cursor.moveToNext());
        }
        cursor.close();
        db.close();
        int totalImagesPerActivityId = imageArray.size();
        Log.e("total", "ImagesPerActivityId is  = " + totalImagesPerActivityId);

        holder.linearLayout=(LinearLayout)row.findViewById(R.id.innerlay);
        for (int i = 0; i <= totalImagesPerActivityId ; i++)
        {
            final ImageView imageView = new ImageView (getContext());
            imageView.setTag(i);
            imageView.setImageResource(R.drawable.img_placeholder);
            holder.linearLayout.addView(imageView);
            imageView.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                    Log.e("Tag",""+imageView.getTag());
                }
            });
        }

        return row;
    }

    class Holder {

        HorizontalScrollView horizontalScrollView;

    }
}

How would i implement HorizontalListView as mentioned ? Thanks to appreciates.

You should remove all Subviews from your Linearlayout before populating new ones:

holder.linearLayout=(LinearLayout)row.findViewById(R.id.innerlay);
holder.linearLayout.removeAllViews();
for (int i = 0; i <= totalImagesPerActivityId ; i++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM