三星S3错误与列表视图 [英] Samsung s3 bug with listview

查看:185
本文介绍了三星S3错误与列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这是一个下拉刷新列表视图,但它呈现出奇怪的错误,每当我试图在我的银河S3运行一个自定义列表视图的工作,它开始说


  

I /编舞(698):跳过340帧!该应用程序可能会做它的主线程的工作太多了。


和列表视图的滚动是痛苦的缓慢。附件是在S3上测试和HTC设备的视频和它的作品完美的HTC。任何指针,之所以会出现这种情况?

HTC: http://www.youtube.com/watch?v=9o1UXv_-合众
S3: http://www.youtube.com/watch?v=YjjC07M70Gk

编辑:code添加

 公共类MainActivity扩展ListActivity实现OnScrollListener {
私人的LinkedList<串GT; mListItems;
TmbResultListViewAdapter适配器;
按钮editButton;
公共静态布尔refreshOnDrag = TRUE;
私人布尔isloading = FALSE;
私人MyTask任务;
PullToRefreshListView LV;
私人进度页脚;
私人TextView中的状态栏。;/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    setRefreshOnPull(真);
    的setContentView(R.layout.activity_main);    的状态栏。=(的TextView)findViewById(R.id.statusbar);    editButton =(按钮)findViewById(R.id.editButton);
    LV =(PullToRefreshListView)getListView();
    lv.setOnRefreshListener(新OnRefreshListener(){
        @覆盖
        公共无效onRefresh(){
            //做工作,在这里刷新列表。
            如果(refreshOnDrag){
                新GetDataTask()执行();
            }
        }
    });
    lv.setOnScrollListener(本);
    lv.setScrollingCacheEnabled(假);
    LayoutInflater吹气=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    页脚=(进度)inflater.inflate(R.layout.footer,NULL);    mListItems =新的LinkedList<串GT;();
    mListItems.addAll(Arrays.asList(mStrings));    // ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,
    // android.R.layout.simple_list_item_1,mListItems);    适配器=新TmbResultListViewAdapter(本);
    setListAdapter(适配器);
}公共无效编辑(视图v){
    如果(!adapter.showEditControlls){
        adapter.showEditControlls = TRUE;
        adapter.notifyDataSetChanged();
        editButton.setText(完成);
    }其他{
        adapter.showEditControlls = FALSE;
        adapter.notifyDataSetChanged();
        editButton.setText(编辑);
    }
}公共无效setRefreshOnPull(布尔VAL){
    this.refreshOnDrag = VAL;
}私有类GetDataTask扩展的AsyncTask<无效,无效的String []> {    @覆盖
    受保护的String [] doInBackground(虚空...... PARAMS){
        //模拟后台作业。
        尝试{
            视频下载(1000);
        }赶上(InterruptedException的E){
            ;
        }
        adapter.resetItems();
        返回mStrings;
    }    @覆盖
    保护无效onPostExecute(的String []的结果){
        mListItems.addFirst(补充说:刷新后......);        //调用onRefreshComplete当列表已刷新。
        ((PullToRefreshListView)getListView())onRefreshComplete();
        super.onPostExecute(结果);
    }
}私有String [] = mStrings {修道院贝洛克
        圣米歇尔杜山宫猫,Abertam,阿邦当斯,Ackawi
        橡果国际,Adelost,Affidelice金夏布利,Afuega'l脾土
        Airag,万能,Aisy CENDRE,的Allgauer埃曼塔尔};@覆盖
公共无效onScroll(AbsListView观点,诠释firstVisibleItem,
        INT visibleItemCount,诠释totalItemCount){    INT loadedItems = firstVisibleItem + visibleItemCount;
    INT偏移量=(((INT)((firstVisibleItem - / adapter.getItemPerPage()))*适配器1)
            .getItemPerPage())+ 1;
    statusBar.setText(OFFSET +的
            +(偏移+ adapter.getItemPerPage() - 1));
    如果((loadedItems == totalItemCount)及&放大器;!isloading){
        如果(任务== NULL ||(task.getStatus()== AsyncTask.Status.FINISHED)){
            任务=新MyTask();
            task.execute();
        }
    }}@覆盖
公共无效onScrollStateChanged(AbsListView观点,诠释scrollState){
    // TODO自动生成方法存根}类MyTask扩展的AsyncTask<太虚,太虚,太虚> {
    @覆盖
    在preExecute保护无效(){
        // TODO自动生成方法存根
        super.on preExecute();
        ((PullToRefreshListView)getListView())addFooterView(页脚)。
        // adapter.notifyDataSetChanged();
    }    @覆盖
    保护无效doInBackground(虚空...... PARAMS){
        isloading = TRUE;
        adapter.loadMoreData();
        //进度PB =新的ProgressBar(getApplicationContext(),空,
        // android.R.attr.progressBarStyleHorizo​​ntal);
        //的LinearLayout linLayout =(LinearLayout中)
        // findViewById(R.id.linearLayout);
        // linLayout.addView(PB);
        Log.d(*****,正在加载...);
        返回null;
    }    @覆盖
    保护无效onPostExecute(虚空结果){
        // adapter.notifyDataSetChanged();
        isloading = FALSE;
        adapter.notifyDataSetChanged();
        ((PullToRefreshListView)getListView())removeFooterView(页脚)。
    }
}@覆盖
公共无效onBack pressed(){
    完();}
}

适配器code添加
我已经看到,当过我尝试滚动跳帧变得更糟。
所以可能是我做了很多工作对getview方法

 公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
    //查看convertView = convertView;
    // TmbJSON eventDetail;    如果(convertView == NULL){
        convertView = inflater.inflate(R.layout.tmb_result_listitem,NULL);
        mViewHolder =新viewHolder();        mViewHolder.resultTitle =(TextView中)convertView
                .findViewById(R.id.resultTitle);
        mViewHolder.resultPeriod =(TextView中)convertView
                .findViewById(R.id.resultPeriod);
        mViewHolder.resultVenue =(TextView中)convertView
                .findViewById(R.id.resultVenue);
        mViewHolder.resultDescription =(TextView中)convertView
                .findViewById(R.id.resultDescription);
        mViewHolder.resultIcon =(ImageView的)convertView
                .findViewById(R.id.resultIcon);
        mViewHolder.checkUnCheckIcon =(ImageView的)convertView
                .findViewById(R.id.checkuncheckicon);
        mViewHolder.layout =(的LinearLayout)convertView.findViewById(R.id.linearLayout);
        mViewHolder.headerTextView =(TextView中)convertView.findViewById(R.id.itemheader);        convertView.setTag(mViewHolder);
    }其他{
        mViewHolder =(viewHolder)convertView.getTag();
    }
    尝试{        mViewHolder.checkUnCheckIcon.setVisibility(showEditControlls ImageView.VISIBLE:ImageView.GONE?);
        mViewHolder.checkUnCheckIcon.setImageResource(mCheckedState.get(位置)R.drawable.starschecked:R.drawable.starsunchecked?);
        mViewHolder.checkUnCheckIcon.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                如果(mCheckedState.get(位置)){
                    mViewHolder.checkUnCheckIcon
                            .setImageResource(R.drawable.starsunchecked);
                    mCheckedState.set(位置,FALSE);
                }否则如果(!mCheckedState.get(位置)){                    mViewHolder.checkUnCheckIcon
                            .setImageResource(R.drawable.starschecked);
                    mCheckedState.set(位置,真正的);
                }
                theAdapter.notifyDataSetChanged();
                Toast.makeText(activity.getApplicationContext(),位置+号事件UN /检查,Toast.LENGTH_LONG).show();
            }
        });
        字符串名称= masterList.get(位置)。名称; // eventDetail.smartStringWithPath(TmbJSON.arrayListObjectWithStrings(名字));
        字符串细节= masterList.get(位置).detail; // eventDetail.smartStringWithPath(TmbJSON.arrayListObjectWithStrings(详细信息));
        字符串场地= masterList.get(位置).venue; // ((JSONObject)eventDetail.object).getJSONArray(\"prs\").getJSONObject(0).getJSONObject(\"loc\").getString(\"name\");
        字符串周期= masterList.get(位置).period; //((JSONObject的)eventDetail.object).getJSONArray(PRS)getJSONObject(0).getString(ts_z);        mViewHolder.resultTitle.setText(名);
        mViewHolder.resultPeriod.setText(期);
        mViewHolder.resultVenue.setText(场地);
        mViewHolder.resultDescription.setText(细节);
        如果((位置)%(itemPerPage)== 0&放大器;&放大器;位置!= 0)
        {mViewHolder.headerTextView.setText((位置+ 1)+(int)的的(位置+ 20));
            mViewHolder.headerTextView.setVisibility(TextView.VISIBLE);
        }
        其他
        {
            mViewHolder.headerTextView.setVisibility(TextView.GONE);        }
        INT forthPos = getCount将() - itemPerPage + 4;
        INT tenthPos = getCount将() - itemPerPage + 10;
        INT sixteenthPos = getCount将() - itemPerPage + 16;    }赶上(例外五){
        e.printStackTrace();
    }
    返回convertView;
}


解决方案

有关的任​​何其他人,面临着同样的还挺发给你将不得不寻找一些地方使用的是大量的内存,在我的情况下,它是在图像列表视图这是造成这个问题,我已经更换为质量较低的之一,其做工精细图像现在,但它仍然超出了我如何做同样的列表视图效果更好下端设备,然后一个高端设备上。除了我。

I have worked on a custom list view which is a pull down to refresh listview but it is showing a strange error , whenever i try to run it on my galaxy s3 , it starts saying

I/Choreographer(698): Skipped 340 frames! The application may be doing too much work on its main thread.

and the scrolling of the listview is painfully slow. Attached is video of testing on s3 and an htc device and it works flawlessly on HTC. Any pointers that why is this happening?

HTC: http://www.youtube.com/watch?v=9o1UXv_-Uco S3: http://www.youtube.com/watch?v=YjjC07M70Gk

edit:code added

public class MainActivity extends ListActivity implements OnScrollListener {
private LinkedList<String> mListItems;
TmbResultListViewAdapter adapter;
Button editButton;
public static boolean refreshOnDrag = true;
private boolean isloading = false;
private MyTask task;
PullToRefreshListView lv;
private ProgressBar footer;
private TextView statusBar;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRefreshOnPull(true);
    setContentView(R.layout.activity_main);

    statusBar = (TextView) findViewById(R.id.statusbar);

    editButton = (Button) findViewById(R.id.editButton);
    lv = (PullToRefreshListView) getListView();
    lv.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Do work to refresh the list here.
            if (refreshOnDrag) {
                new GetDataTask().execute();
            }
        }
    });
    lv.setOnScrollListener(this);
    lv.setScrollingCacheEnabled(false);
    LayoutInflater inflater = (LayoutInflater)     getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    footer = (ProgressBar) inflater.inflate(R.layout.footer, null);

    mListItems = new LinkedList<String>();
    mListItems.addAll(Arrays.asList(mStrings));

    // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    // android.R.layout.simple_list_item_1, mListItems);

    adapter = new TmbResultListViewAdapter(this);
    setListAdapter(adapter);
}

public void edit(View v) {
    if (!adapter.showEditControlls) {
        adapter.showEditControlls = true;
        adapter.notifyDataSetChanged();
        editButton.setText("Done");
    } else {
        adapter.showEditControlls = false;
        adapter.notifyDataSetChanged();
        editButton.setText("Edit");
    }
}

public void setRefreshOnPull(boolean val) {
    this.refreshOnDrag = val;
}

private class GetDataTask extends AsyncTask<Void, Void, String[]> {

    @Override
    protected String[] doInBackground(Void... params) {
        // Simulates a background job.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            ;
        }
        adapter.resetItems();
        return mStrings;
    }

    @Override
    protected void onPostExecute(String[] result) {
        mListItems.addFirst("Added after refresh...");

        // Call onRefreshComplete when the list has been refreshed.
        ((PullToRefreshListView) getListView()).onRefreshComplete();
        super.onPostExecute(result);
    }
}

private String[] mStrings = { "Abbaye de Belloc",
        "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
        "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu",
        "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" };

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

    int loadedItems = firstVisibleItem + visibleItemCount;
    int offSet = (((int) ((firstVisibleItem - 1) / adapter.getItemPerPage())) *  adapter
            .getItemPerPage()) + 1;
    statusBar.setText(offSet + " of "
            + (offSet + adapter.getItemPerPage() - 1));
    if ((loadedItems == totalItemCount) && !isloading) {
        if (task == null || (task.getStatus() == AsyncTask.Status.FINISHED)) {
            task = new MyTask();
            task.execute();
        }
    }

}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    // TODO Auto-generated method stub

}

class MyTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        ((PullToRefreshListView) getListView()).addFooterView(footer);
        // adapter.notifyDataSetChanged();
    }

    @Override
    protected Void doInBackground(Void... params) {
        isloading = true;
        adapter.loadMoreData();
        // ProgressBar pb = new ProgressBar(getApplicationContext(), null,
        // android.R.attr.progressBarStyleHorizontal);
        // LinearLayout linLayout = (LinearLayout)
        // findViewById(R.id.linearLayout);
        // linLayout.addView(pb);
        Log.d("*****", "Loading...");
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // adapter.notifyDataSetChanged();
        isloading = false;
        adapter.notifyDataSetChanged();
        ((PullToRefreshListView) getListView()).removeFooterView(footer);
    }
}

@Override
public void onBackPressed() {
    finish();

}
}

adapter code added I have seen that when ever i try to scroll the skipping frames get even worse. so may be i am doing a lot of work on the getview method

    public View getView(final int position, View convertView, ViewGroup parent) {
    //View convertView = convertView;
    // TmbJSON eventDetail;

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.tmb_result_listitem, null);
        mViewHolder = new viewHolder();

        mViewHolder.resultTitle = (TextView) convertView
                .findViewById(R.id.resultTitle);
        mViewHolder.resultPeriod = (TextView) convertView
                .findViewById(R.id.resultPeriod);
        mViewHolder.resultVenue = (TextView) convertView
                .findViewById(R.id.resultVenue);
        mViewHolder.resultDescription = (TextView) convertView
                .findViewById(R.id.resultDescription);
        mViewHolder.resultIcon = (ImageView) convertView
                .findViewById(R.id.resultIcon);
        mViewHolder.checkUnCheckIcon = (ImageView) convertView
                .findViewById(R.id.checkuncheckicon);
        mViewHolder.layout = (LinearLayout) convertView.findViewById(R.id.linearLayout);
        mViewHolder.headerTextView = (TextView) convertView.findViewById(R.id.itemheader);

        convertView.setTag(mViewHolder);
    } else {
        mViewHolder = (viewHolder) convertView.getTag();
    }
    try {

        mViewHolder.checkUnCheckIcon.setVisibility(showEditControlls ? ImageView.VISIBLE : ImageView.GONE);
        mViewHolder.checkUnCheckIcon.setImageResource(mCheckedState.get(position) ? R.drawable.starschecked : R.drawable.starsunchecked);
        mViewHolder.checkUnCheckIcon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (mCheckedState.get(position)) {
                    mViewHolder.checkUnCheckIcon
                            .setImageResource(R.drawable.starsunchecked);
                    mCheckedState.set(position, false);
                } else if (!mCheckedState.get(position)) {

                    mViewHolder.checkUnCheckIcon
                            .setImageResource(R.drawable.starschecked);
                    mCheckedState.set(position, true);
                }
                theAdapter.notifyDataSetChanged();
                Toast.makeText(activity.getApplicationContext(), position+"th Event un/checked", Toast.LENGTH_LONG).show();
            }
        });


        String name = masterList.get(position).name;// eventDetail.smartStringWithPath(TmbJSON.arrayListObjectWithStrings("name"));
        String detail = masterList.get(position).detail;// eventDetail.smartStringWithPath(TmbJSON.arrayListObjectWithStrings("detail"));
        String venue = masterList.get(position).venue;// ((JSONObject)eventDetail.object).getJSONArray("prs").getJSONObject(0).getJSONObject("loc").getString("name");
        String period = masterList.get(position).period;// ((JSONObject)eventDetail.object).getJSONArray("prs").getJSONObject(0).getString("ts_z");

        mViewHolder.resultTitle.setText(name);
        mViewHolder.resultPeriod.setText(period);
        mViewHolder.resultVenue.setText(venue);
        mViewHolder.resultDescription.setText(detail);
        if((position) % (itemPerPage) == 0 && position!=0)
        {   mViewHolder.headerTextView.setText((position+1)+" of "+(int)(position+20));
            mViewHolder.headerTextView.setVisibility(TextView.VISIBLE);
        }
        else
        {
            mViewHolder.headerTextView.setVisibility(TextView.GONE);

        }
        int forthPos = getCount() - itemPerPage + 4;
        int tenthPos = getCount() -  itemPerPage + 10;
        int sixteenthPos = getCount() - itemPerPage + 16;

    } catch (Exception e) {
        e.printStackTrace();
    }




    return convertView;
}

解决方案

For any one else , facing the same kinda issue you will have to look some where you are using a lot of memory , in my case it was the image in listview that was causing the issue , i have replaced the image with a lower quality one and its working fine now , But its still beyond me that how does same list view works better on a lower end device then a higher end device. Beyond me .

这篇关于三星S3错误与列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆