GVKun编程网logo

如何将显示的sql数据加载到wpf可滚动列表视图中?大集合(超过20k)而不会遇到内存问题?

19

在本文中,我们将给您介绍关于如何将显示的sql数据加载到wpf可滚动列表视图中?大集合的详细内容,并且为您解答超过20k而不会遇到内存问题?的相关问题,此外,我们还将为您提供关于android–Fir

在本文中,我们将给您介绍关于如何将显示的sql数据加载到wpf可滚动列表视图中?大集合的详细内容,并且为您解答超过20k而不会遇到内存问题?的相关问题,此外,我们还将为您提供关于android – Firebase无限滚动列表视图滚动加载10项、android – 在DialogPreference中实现固定高度可滚动列表视图、android – 如何解析JSON对象并将其显示在列表视图中?、c# – 如何将文件加载到blob中而不先加载到RAM中?的知识。

本文目录一览:

如何将显示的sql数据加载到wpf可滚动列表视图中?大集合(超过20k)而不会遇到内存问题?

如何将显示的sql数据加载到wpf可滚动列表视图中?大集合(超过20k)而不会遇到内存问题?

我在sql数据库中有一个大集合。当我使用时DataSet,我假设我立即提取所有(当我说全部时,我的意思是20000+)数据库条目以填充可滚动的WPF列表视图。当我提取那么多数据并添加更多数据时,我的内存不足。

当用户滚动时,我如何只提取所需的数据?会DataRead在这里工作吗?我看过有关DataRead的教程,但它们通常基于按钮,并且我需要根据用户在列表视图中滚动的方向来动态读取数据。

有没有一种方法可以基于(例如)30个值进行更新,如果用户看到其中的15个,则服务器查询和返回值之间的滞后不会导致列表视图在用户向上滚动时出现任何问题还是下降?

答案1

小编典典

请检查下一个链接codeProject中的数据虚拟化

android – Firebase无限滚动列表视图滚动加载10项

android – Firebase无限滚动列表视图滚动加载10项

参见英文答案 > Get the data from the Firebase in limit to perform pull to refresh and load more functionality                                    2个
我正在寻找一种方法来实现在我的Firebase应用程序中滚动的简单列表视图,但我没有找到任何方法如何实现它.我已经在互联网上尝试了2-3个教程和文档,但没有达到要求的结果.

在我的应用程序中,我希望滚动像开始前10个列表项加载然后每次滚动接下来10或20项将加载,直到最后一项出现在列表的底部.

所以我尝试通过以下方式检索前10个项目:

ArrayList<Event> event=new ArrayList<>();

Dbref = FirebaseDatabase.getInstance().getReference("/event");
Dbref.startAt(1).limitToLast(10).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Log.e("Events.java ", "range query started! : " + dataSnapshot.getChildrenCount());
                String event_id = snapshot.child("details").child("event_id").getValue().toString();
                e=new Event(event_id); //Event is a model class for list items
                event.add(e);
                Log.e("ShowEventInfo : ", "" + event_id);
            }
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    adapter=new Event_CustomAdapter(getActivity(),event); 
    ls.setAdapter(adapter); //here ls is instance of ListView

我推荐这个Youtube视频来实现这个功能:
(https://www.youtube.com/watch?annotation_id=annotation_3916642001&feature=iv&src_vid=YMJSBHAZsso&v=XwIKb_f0Y_w)

在上面的代码中,正如您所看到的,我正在生成Log以检查是否从firebase获取了数据,但是我没有输出Android监视器.

我不知道如何在列表视图中实现Firebase滚动.我认为对于那些在回收站视图/列表视图中实现无限滚动的人来说,这是一个常见问题.

你能帮我实现这个功能吗?谢谢.

解决方法:

这里我们将使用DatabaseReference;的limitToFirst(int)或limitToLast(int)方法从FireBase获取第一个或最后一个记录.

在下面的示例中,我使用limitToFirst(int)仅从Firebase获取最高指定记录.在这里,我正在使用oldestPostId,这是我们记录的最后一个或第十个键.

  private String oldestPostId;
  DatabaseReference Dbref = FirebaseDatabase.getInstance().getReference("/event");


  /////GETTING FirsT 10 RECORDS FROM THE FIREBASE HERE

        Dbref.limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot child : dataSnapshot.getChildren()) {

                    oldestPostId = child.getKey(); ////HERE WE ARE SAVING THE LAST POST_ID FROM URS POST

                    dataSnapshot.getChildrenCount());
                    String event_id = snapshot.child("details").child("event_id").getValue().toString();
                    e=new Event(event_id); //Event is a model class for list items
                    event.add(e);
                    Log.e("ShowEventInfo : ", "" + event_id);
                }      
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

从上面的代码,我已经从firebase获得前10条记录,现在我们将实现加载更多功能,所以我使用Listview的onscrolllistener
在isScrollCompleted()上,我们将使用orderByKey()通过limitToFirst()方法进一步获取10条记录.我已经实现了整个代码以获取有关isScrollCompleted()的更多数据,请查看以下示例.

YOUR_LISTVIEW.setonScrollListener(new OnScrollListener() {
    private int currentVisibleItemCount;
    private int currentScrollState;
    private int currentFirstVisibleItem;
    private int totalItem;
    private LinearLayout lBelow;


    @Override
    public void onScrollStateChanged (AbsListView view,int scrollState){
        // Todo Auto-generated method stub
        this.currentScrollState = scrollState;
        this.isScrollCompleted();
    }

    @Override
    public void onScroll (AbsListView view,int firstVisibleItem,
    int visibleItemCount, int totalItemCount){
        // Todo Auto-generated method stub
        this.currentFirstVisibleItem = firstVisibleItem;
        this.currentVisibleItemCount = visibleItemCount;
        this.totalItem = totalItemCount;


    }

    private void isScrollCompleted () {
        if (totalItem - currentFirstVisibleItem == currentVisibleItemCount
                && this.currentScrollState == SCROLL_STATE_IDLE) {
            /** To do code here*/
            Dbref.orderByKey().startAt(oldestPostId).limitToFirst(10).addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for (DataSnapshot child : dataSnapshot.getChildren()) {

                        oldestPostId = child.getKey();
                        String event_id = snapshot.child("details").child("event_id").getValue().toString();
                        e = new Event(event_id); //Event is a model class for list items
                        event.add(e);
                        Log.e("ShowEventInfo : ", "" + event_id);
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

        }
    });

});

android – 在DialogPreference中实现固定高度可滚动列表视图

android – 在DialogPreference中实现固定高度可滚动列表视图

我已经对DialogPreference进行了细分,并使用ListView实现了一个文件夹选择器.当在文件夹树中上下移动并在列表视图中显示文件夹时,一切都运行良好.

我的问题是,当我在文件夹树中上下移动时,对话框窗口会增大和缩小(由于每个文件夹中的子文件夹数量不同).我希望在导航文件夹树时将对话框窗口保持固定的高度.

作为一个解决方案,我为列表视图指定了一个固定的高度,这在纵向模式下运行良好,但是我注意到当我切换到横向模式时,listview不会滚动,我能想出的唯一原因是列表视图中的项目小于固定高度,因此未启用滚动.这有点痛苦,因为它在横向模式下截断列表,用户无法向下滚动以查看列表项的其余部分.

有没有人有什么建议?我并不是太忙于使用对话框(全屏演示也没问题),所以在PreferencesActivity中可以使用的任何替代方案都可以.

提前致谢,
dsana123.

解决方法

您可以动态设置列表视图的高度.
看到
How can I put a ListView into a ScrollView without it collapsing?

所以,你可以像这样解决问题.

>设置对话框的高度
>在scrollview中添加listview
>动态设置listview的高度.

如果您按照上面的步骤操作,则可以在横向模式下滚动包含listview的滚动视图.

android – 如何解析JSON对象并将其显示在列表视图中?

android – 如何解析JSON对象并将其显示在列表视图中?

以下是我遇到问题的代码. PHP文件就像一个魅力,你可以看到你是否转到了url_all_dates变量所持有的值.这个类下面是list_item的.xml布局文件.该应用程序运行但不显示数据库中的任何日期:

public class RequestTour extends ListActivity {

    // Progress Dialog
    private ProgressDialog pDialog;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> datesList;

    // url to get all dates list
    private static String url_all_dates = "http://www.prayingmantesconcepts.com/androidfinal/get_all_avail_dates.PHP";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_DATES = "dates";
    private static final String TAG_DATEID = "dateID";
    private static final String TAG_DATE = "date";

    // dates JSONArray
    JSONArray dates = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dates);//put dates layout here.

        // Hashmap for ListView
        datesList = new ArrayList<HashMap<String, String>>();

        // Loading dates in Background Thread
        new LoadAllDates().execute();

        // Get listview
        ListView lv = getListView();

        // on seleting single date
        // launching Book Tour Screen
        lv.setonItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String dateID = ((TextView) view.findViewById(R.id.dateID)).getText()
                        .toString();

                // Starting new intent
                Intent in = new Intent(getApplicationContext(),
                        BookTour.class);
                // sending dateID to next activity
                in.putExtra(TAG_DATEID, dateID);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        });

    }

    // Response from Edit Product Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received 
            // means user booked a tour
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

    /**
     * Background Async Task to Load all dates by making HTTP Request
     * */
    class LoadAllDates extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(RequestTour.this);
            pDialog.setMessage("Loading dates. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All dates from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_dates, "GET", params);

            // Check your log cat for JSON response
            Log.d("All Dates: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    //  found
                    // Getting Array of 
                     dates = json.getJSONArray(TAG_DATES);

                    // looping through All Dates Available for Request
                    for (int i = 0; i < dates.length(); i++) {
                        JSONObject c = dates.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_DATEID);
                        String date = c.getString(TAG_DATE);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_DATEID, id);
                        map.put(TAG_DATE, date);

                        // adding HashList to ArrayList
                        datesList.add(map);
                    }
                } else {
                    // no  found
                    // Launch Add New product Activity
                    Intent i = new Intent(getApplicationContext(),
                            Main.class);
                    // Closing all prevIoUs activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printstacktrace();
            }

            return null;
        }

        /**
         * After completing background task dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all 
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    listadapter adapter = new SimpleAdapter(
                            RequestTour.this, datesList,
                            R.layout.list_item, new String[] { TAG_DATEID,
                                    TAG_DATE},
                            new int[] { R.id.dateID, R.id.date });
                    // updating listview
                    setlistadapter(adapter);
                }
            });

        }

    }
}


<!------------------------------------------------------------------------------------>


list_item.xml:

<?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:orientation="vertical" >

    <!-- Date id (dateID) - will be HIDDEN - used to pass to other activity -->
    <TextView
        android:id="@+id/dateID"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />


    <!-- Date Label -->
    <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="6dip"
        android:paddingLeft="6dip"
        android:textSize="17dip"
        android:text/>

</LinearLayout>

解决方法:

首要问题 :
这里

            // no  found
            // Launch Add New product Activity
            Intent i = new Intent(getApplicationContext(),
                    Main.class);
            // Closing all prevIoUs activities
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);

您正在尝试从后台Thread访问Ui元素.在doInBackground完成后,将这些代码行移动到onPostExecute以从AsyncTask更新UI.

第二个问题:

这里

  protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all 
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */

                }
            });

因为我们能够访问AsyncTask的onPostExecute方法中的UI元素,所以不需要使用runOnUiThread来更新onPostExecute中的UI元素,就像您尝试在onPostExecute中使用runOnUiThread中的访问listadapter或ListView一样

解决方案

通过正确使用AsyncTask更改LoadAllDates代码:

class LoadAllDates extends AsyncTask<String, String,
                                    ArrayList<HashMap<String, String>>> {
    datesList=new ArrayList<HashMap<String, String>>;
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
          //YOUR CODE HERE
        }


        protected ArrayList<HashMap<String, String>> 
                                doInBackground(String... args) {
         // Building Parameters
         List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = 
                    jParser.makeHttpRequest(url_all_dates, "GET", params);

            // Check your log cat for JSON response
            Log.d("All Dates: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    //  found
                    // Getting Array of 
                     dates = json.getJSONArray(TAG_DATES);

                    // looping through All Dates Available for Request
                    for (int i = 0; i < dates.length(); i++) {
                        JSONObject c = dates.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_DATEID);
                        String date = c.getString(TAG_DATE);

                        // creating new HashMap
                        HashMap<String, String> map = 
                                    new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_DATEID, id);
                        map.put(TAG_DATE, date);

                        // adding HashList to ArrayList
                        datesList.add(map);
                    }
                } else {
                    // no  found

                }
            } catch (JSONException e) {
                e.printstacktrace();
            }

            return ArrayList<HashMap<String, String>>;
        }

        /**
         * After completing background task dismiss the progress dialog
         * **/
        protected void onPostExecute(
                     ArrayList<HashMap<String, String>> file_url) {
            // dismiss the dialog after getting all 
            pDialog.dismiss();
            // updating UI from Background Thread

                  if(file_url.size()>0)
                   {
                    listadapter adapter = new SimpleAdapter(
                            RequestTour.this, file_url,
                            R.layout.list_item, new String[] { TAG_DATEID,
                                    TAG_DATE},
                            new int[] { R.id.dateID, R.id.date });
                    // updating listview
                    setlistadapter(adapter);
                  }
                 else{
                    // Launch Add New product Activity
                    Intent i = new Intent(getApplicationContext(),
                            Main.class);
                    // Closing all prevIoUs activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    }


        }

    }

c# – 如何将文件加载到blob中而不先加载到RAM中?

c# – 如何将文件加载到blob中而不先加载到RAM中?

我正在使用C#,我无法将大文件加载到二进制字段使用字节数组.

基本上,如果我加载的文件太大,我会遇到内存问题.

有没有办法在不使用大量ram的情况下将文件加载到二进制字段中,即避免先将文件加载到内存中?

如果它有帮助,我使用的是Advantage Database Server,这是使用winforms应用程序而不是Web应用程序.

问候

解决方法

AdsExtendedReader.SetBytes可用于以块的形式加载blob.它封装了Jeremy提到的对AdsSetBinary()的调用.

见AdsExtendedReader.SetBytes.

关于如何将显示的sql数据加载到wpf可滚动列表视图中?大集合超过20k而不会遇到内存问题?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于android – Firebase无限滚动列表视图滚动加载10项、android – 在DialogPreference中实现固定高度可滚动列表视图、android – 如何解析JSON对象并将其显示在列表视图中?、c# – 如何将文件加载到blob中而不先加载到RAM中?等相关知识的信息别忘了在本站进行查找喔。

本文标签: