简体   繁体   English

更新Android列表视图中的水平滚动视图

[英]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(); 我正在从SQlite的ListView中开发一个horizo​​ntalListView的应用程序。当我向下滚动ListView时,我的horizo​​ntallistview将通过两次输入来增加。我已经尝试使用adapter.notifyDataSetChanged();。 ,but it not effect on horizontalListView.Any thoughts on how i should go about doing this. ,但是对horizo​​ntalListView无效。关于我应该怎么做的任何想法。

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 这是带有Horizo​​ntalListView的Adapter getView()方法

@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 ? 我将如何实现提到的Horizo​​ntalListView? Thanks to appreciates. 感谢感谢。

You should remove all Subviews from your Linearlayout before populating new ones: 在填充新的子视图之前,应从Linearlayout中删除所有子视图:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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