安卓-adapter无法绑定数据,get(poiniton)无法获取到数据

问题描述

adapter无法绑定数据,get(poiniton)无法获取到数据

要实现一个像通讯录一样的listview


public class MyDistributor2Activity extends BaseActivity {

    @InjectView(R.id.my_distributor_lv)
    PinnedHeaderNoScrollListViewTest distributor_lv;

    LayoutInflater layoutInflater;

    MyDistributor2 MyDistributor2;

    DistributorPinnedHeaderAdapter distributorAdapter;

    RequestQueue queue;

    MyDistributor2 distributor;

    // unsorted list items
    ArrayList<MyDistributor2> mItems = new ArrayList<MyDistributor2>();

    // array list to store section positions
    ArrayList<Integer> mListSectionPos;

    // array list to store listView data
    ArrayList<MyDistributor2> mListItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.sec_my_distributor_list2);

        ButterKnife.inject(this);

        // Array to ArrayList
        mListSectionPos = new ArrayList<Integer>();

        mListItems = new ArrayList<MyDistributor2>();

        queue = VolleyQuery.getQueue(this);

        layoutInflater = LayoutInflater.from(this);

        getDate("first");

        findDistributor();

    }

  //===查询得到到的数据,删除了部分代码
    public void getDate(final String method) {

        url = ConfigStr.api_base + "myself/myDistributor";

        StringUTF8Request request = new StringUTF8Request(
                Request.Method.POST,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        dialog.dismiss();

                        byte[] bytes = Base64.decode(response, Base64.DEFAULT);

                        String result = new String(bytes);

                        Log.d("result_add", result);
                        try {
                            JSONObject jsonObject = new JSONObject(result);

                            String json = jsonObject.getString("RS100065");

                            Gson gson = new Gson();

                                mItems = gson.fromJson(json, new TypeToken<List<MyDistributor2>>() {
                                }.getType());

                                new Poplulate().execute(mItems);

                        } catch (Exception e) {
/
                        }

                    }
                },

        queue.add(request);
    }

    private void setAdapter(ArrayList<MyDistributor2> myDistributor2) {

        distributorAdapter = new DistributorPinnedHeaderAdapter(MyDistributor2Activity.this, myDistributor2, mListSectionPos);

         distributor_lv.setAdapter(distributorAdapter);

    }

    // sort array and extract sections in background Thread here we use
    // AsyncTask
    private class Poplulate extends AsyncTask<ArrayList<MyDistributor2>, ArrayList<MyDistributor2>, ArrayList<MyDistributor2>> {

        private void showLoading(View contentView) {
            contentView.setVisibility(View.GONE);
        }

        private void showContent(View contentView) {
            contentView.setVisibility(View.VISIBLE);
        }

        private void showEmptyText(View contentView) {
            contentView.setVisibility(View.GONE);
        }

        @Override
        protected void onPreExecute() {
            showLoading(distributor_lv);
            super.onPreExecute();
        }

        @Override
        protected ArrayList<MyDistributor2> doInBackground(ArrayList<MyDistributor2>... params) {

            return cacalation(params[0]);
        }

        @Override
        protected void onPostExecute(ArrayList<MyDistributor2> result) {
            if (!isCancelled()) {
                if (result.size() <= 0) {
                    showEmptyText(distributor_lv);
                } else {
                    showContent(distributor_lv);
                }

                setAdapter(result);
            }
            super.onPostExecute(result);
        }
    }

    public class SortIgnoreCase implements Comparator<MyDistributor2> {
        public int compare(MyDistributor2 s1, MyDistributor2 s2) {
            return s1.getInvite_code().compareToIgnoreCase(s2.getInvite_code());
        }
    }

}

public class DistributorPinnedHeaderAdapter extends BaseAdapter implements /*OnScrollListener,*/ IPinnedHeader, Filterable {

    private static final int TYPE_ITEM = 0;
    private static final int TYPE_SECTION = 1;
    private static final int TYPE_MAX_COUNT = TYPE_SECTION + 1;

    private static String mem_letter;

    private Filter filter;

    Context mContext;

    LayoutInflater mLayoutInflater;

    int mCurrentSectionPosition = 0, mNextSectionPostion = 0;

    // array list to store section positions
    ArrayList<Integer> mListSectionPos;

    ArrayList<MyDistributor2> mListItems;

    BottomPopUp bottomPopUp2;

    public DistributorPinnedHeaderAdapter(Context context, ArrayList<MyDistributor2> listItems, ArrayList<Integer> listSectionPos) {
        this.mContext = context;
        this.mListItems = listItems;
        this.mListSectionPos = listSectionPos;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mListItems.size();
    }

    @Override
    public boolean areAllItemsEnabled() {
        return false;
    }

    @Override
    public boolean isEnabled(int position) {
        return !mListSectionPos.contains(position);
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_MAX_COUNT;
    }

    @Override
    public int getItemViewType(int position) {
        return mListSectionPos.contains(position) ? TYPE_SECTION : TYPE_ITEM;
    }

    @Override
    public Object getItem(int position) {
        return mListItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return mListItems.get(position).hashCode();
    }

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

        ViewHolder holder = null;

        if (convertView == null) {

            holder = new ViewHolder();

            int type = getItemViewType(position);

            switch (type) {
                case TYPE_ITEM://内容部分

                    convertView = mLayoutInflater.inflate(R.layout.sec_my_distributor_list_item, null);

                    holder.text_name = (TextView) convertView.findViewById(R.id.my_distributor_item_text_name);

                    holder.text_tel = (TextView) convertView.findViewById(R.id.my_distributor_item_text_tel);

                    holder.text_mshopname = (TextView) convertView.findViewById(R.id.my_distributor_item_text_mshopname);

                    break;
                case TYPE_SECTION://头部分类部分

                    convertView = mLayoutInflater.inflate(R.layout.section_row_view, null);

                    break;
            }

            convertView.setTag(holder);

        } else {

            if(convertView.getTag() instanceof ViewHolder){

                holder = (ViewHolder) convertView.getTag();

            }else{

                holder=new ViewHolder();

                int type = getItemViewType(position);

                switch (type) {
                    case TYPE_ITEM:

                        convertView = mLayoutInflater.inflate(R.layout.sec_my_distributor_list_item, null);

                        holder.text_name = (TextView) convertView.findViewById(R.id.my_distributor_item_text_name);

                        holder.text_tel = (TextView) convertView.findViewById(R.id.my_distributor_item_text_tel);

                        holder.text_mshopname = (TextView) convertView.findViewById(R.id.my_distributor_item_text_mshopname);

                        break;
                    case TYPE_SECTION:

                        convertView = mLayoutInflater.inflate(R.layout.section_row_view, null);

                        break;
                }

            }
        }

        //===设置列表内容各项值

        MyDistributor2 distributor = mListItems.get(position);//此处无法获得数据,下面的控件无法绑定数据?

        holder.text_name.setText(distributor.getStaff_real_name());
        holder.text_tel.setText(distributor.getStaff_partner_phonenum());
       holder.text_mshopname.setText(distributor.getStaff_departments_name());

        return convertView;
    }

    @Override
    public int getPinnedHeaderState(int position) {

        if (getCount() == 0 || position < 0 || mListSectionPos.indexOf(position) != -1) {
            return PINNED_HEADER_GONE;
        }

        mNextSectionPostion = getNextSectionPosition(mCurrentSectionPosition);
        if (mNextSectionPostion != -1 && position == mNextSectionPostion - 1) {
            return PINNED_HEADER_PUSHED_UP;
        }

        return PINNED_HEADER_VISIBLE;
    }

    public int getNextSectionPosition(int currentSectionPosition) {
        int index = mListSectionPos.indexOf(currentSectionPosition);
        if ((index + 1) < mListSectionPos.size()) {
            return mListSectionPos.get(index + 1);
        }
        return mListSectionPos.get(index);
    }

    public static class ViewHolder {
        public TextView textView;

        public TextView sub_textView;

        TextView text_name;

        TextView text_tel;

        TextView text_mshopname;

    }

}

解决方案

activity完整代码

 public class MyDistributor2Activity extends BaseActivity {

    @InjectView(R.id.my_distributor_lv)
    PinnedHeaderNoScrollListViewTest distributor_lv;

    LayoutInflater layoutInflater;

    MyDistributor2 MyDistributor2;

    DistributorPinnedHeaderAdapter distributorAdapter;

    RequestQueue queue;

    MyDistributor2 distributor;

    // unsorted list items
    ArrayList<MyDistributor2> mItems = new ArrayList<MyDistributor2>();

    // array list to store section positions
    ArrayList<Integer> mListSectionPos;

    // array list to store listView data
    ArrayList<MyDistributor2> mListItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.sec_my_distributor_list2);

        ButterKnife.inject(this);

        // Array to ArrayList
        mListSectionPos = new ArrayList<Integer>();

        mListItems = new ArrayList<MyDistributor2>();

        queue = VolleyQuery.getQueue(this);

        layoutInflater = LayoutInflater.from(this);

        getDate("first");

        findDistributor();

    }

  //===查询得到到的数据,删除了部分代码
    public void getDate(final String method) {

        url = ConfigStr.api_base + "myself/myDistributor";

        StringUTF8Request request = new StringUTF8Request(
                Request.Method.POST,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        dialog.dismiss();

                        byte[] bytes = Base64.decode(response, Base64.DEFAULT);

                        String result = new String(bytes);

                        Log.d("result_add", result);
                        try {
                            JSONObject jsonObject = new JSONObject(result);

                            String json = jsonObject.getString("RS100065");

                            Gson gson = new Gson();

                                mItems = gson.fromJson(json, new TypeToken<List<MyDistributor2>>() {
                                }.getType());

                                new Poplulate().execute(mItems);

                        } catch (Exception e) {
/
                        }

                    }
                },

        queue.add(request);
    }

    private void setAdapter(ArrayList<MyDistributor2> myDistributor2) {

        distributorAdapter = new DistributorPinnedHeaderAdapter(MyDistributor2Activity.this, myDistributor2, mListSectionPos);

         distributor_lv.setAdapter(distributorAdapter);

    }

    // sort array and extract sections in background Thread here we use
    // AsyncTask
    private class Poplulate extends AsyncTask<ArrayList<MyDistributor2>, ArrayList<MyDistributor2>, ArrayList<MyDistributor2>> {

        private void showLoading(View contentView) {
            contentView.setVisibility(View.GONE);
        }

        private void showContent(View contentView) {
            contentView.setVisibility(View.VISIBLE);
        }

        private void showEmptyText(View contentView) {
            contentView.setVisibility(View.GONE);
        }

        @Override
        protected void onPreExecute() {
            showLoading(distributor_lv);
            super.onPreExecute();
        }

        @Override
        protected ArrayList<MyDistributor2> doInBackground(ArrayList<MyDistributor2>... params) {

            return cacalation(params[0]);
        }

        @Override
        protected void onPostExecute(ArrayList<MyDistributor2> result) {
            if (!isCancelled()) {
                if (result.size() <= 0) {
                    showEmptyText(distributor_lv);
                } else {
                    showContent(distributor_lv);
                }

                setAdapter(result);
            }
            super.onPostExecute(result);
        }
    }

    public class SortIgnoreCase implements Comparator<MyDistributor2> {
        public int compare(MyDistributor2 s1, MyDistributor2 s2) {
            return s1.getInvite_code().compareToIgnoreCase(s2.getInvite_code());
        }
    }

    private ArrayList<MyDistributor2> cacalation(ArrayList<MyDistributor2>... params) {

        ArrayList<MyDistributor2> myDistributor2 = new ArrayList<>();

        mListSectionPos.clear();

        ArrayList<MyDistributor2> items = params[0];

        if (mItems.size() > 0) {

            // NOT forget to sort array
            Collections.sort(items, new SortIgnoreCase());

            String prev_section = "";

            for (MyDistributor2 current_item : items) {// Invite_code--首字母

                String current_section = current_item.getInvite_code().toUpperCase(Locale.getDefault());

                if (!prev_section.equals(current_section)) {

                    MyDistributor2 myDistributor2_test = new MyDistributor2();

                    myDistributor2_test.setInvite_code(current_section);

                    myDistributor2.add(myDistributor2_test);

                    myDistributor2.add(current_item);

                    // array list of section positions
                    mListSectionPos.add(myDistributor2.indexOf(myDistributor2_test));

                    prev_section = current_section;

                } else {

                    myDistributor2.add(current_item);
                }
            }

        }
        return myDistributor2;
    }

}

解决方案二:

你说得获取不到数据是什么情况?数组越界?空指针?还是根本没走到那一步?

解决方案三:

mItems = gson.fromJson(json, new TypeToken>() {}.getType());你遍历一下mitems里面的元素是否为空值

解决方案四:

这是错误日志,我打印了 mListItems.get(position),它获取到的是个空值,

  java.lang.NullPointerException
            at com.bkrtrip.lxb.adapter.my.DistributorPinnedHeaderAdapter.getView(DistributorPinnedHeaderAdapter.java:246)
            at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
            at android.widget.AbsListView.obtainView(AbsListView.java:2124)
            at android.widget.ListView.makeAndAddView(ListView.java:1787)
            at android.widget.ListView.fillDown(ListView.java:675)
            at android.widget.ListView.fillFromTop(ListView.java:735)
            at android.widget.ListView.layoutChildren(ListView.java:1640)
            at android.widget.AbsListView.onLayout(AbsListView.java:1954)
            at com.bkrtrip.lxb.view.selectlistview.PinnedHeaderNoScrollListViewTest.onLayout(PinnedHeaderNoScrollListViewTest.java:150)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at me.imid.swipebacklayout.lib.SwipeBackLayout.onLayout(SwipeBackLayout.java:386)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
            at android.view.View.layout(View.java:11314)
            at android.view.ViewGroup.layout(ViewGroup.java:4234)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1496)
            at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2449)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4430)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
            at dalvik.system.NativeStart.main(Native Method)

PinnedHeaderNoScrollListViewTest这是我用到的带有头部分类效果的listview,报错的代码是再onlyout方法中的super.onLayout(changed, left, top, right, bottom);

 /*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// modified by @author Bhavya Mehta
package com.bkrtrip.lxb.view.selectlistview;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.bkrtrip.lxb.R;
import com.bkrtrip.lxb.adapter.apply.CustomerPinnedHeaderAdapter;
import com.bkrtrip.lxb.adapter.my.DistributorPinnedHeaderAdapter;
import com.bkrtrip.lxb.view.selectlistview.inter.IIndexBarFilter;
import com.bkrtrip.lxb.view.selectlistview.inter.IPinnedHeader;

/*
 * A ListView that maintains a header pinned at the top of the list. The
 * pinned header can be pushed up and dissolved as needed.
 */
public class PinnedHeaderNoScrollListViewTest extends ListView implements IIndexBarFilter {

    // interface object that configure pinned header view position in list view
    IPinnedHeader mAdapter;

    // view objects
    View mHeaderView,mIndexBarView,mPreviewTextView;

    // flags that decide view visibility
    boolean mHeaderVisibility=false;
    boolean mPreviewVisibility=false;
    // initially show index bar view with it's content
    boolean mIndexBarVisibility=true;

    // context object
    Context mContext;

    // view height and width
    int mHeaderViewWidth,
        mHeaderViewHeight,
        mIndexBarViewWidth,
        mIndexBarViewHeight,
        mIndexBarViewMarginTop,
        mIndexBarViewMargin,
        mPreviewTextViewWidth,
        mPreviewTextViewHeight;

    // touched index bar Y axis position used to decide preview text view position
    float mIndexBarY;

    public PinnedHeaderNoScrollListViewTest(Context context) {
        super(context);
        this.mContext = context;
    }

    public PinnedHeaderNoScrollListViewTest(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
    }

    public PinnedHeaderNoScrollListViewTest(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mContext = context;
    }

    public View getmIndexBarView() {
        return mIndexBarView;
    }

    @Override
    public void setAdapter(ListAdapter adapter) {
        this.mAdapter = (DistributorPinnedHeaderAdapter)adapter;
        super.setAdapter(adapter);
    }

    public void setPinnedHeaderView(View headerView) {
         this.mHeaderView = headerView;
        // Disable vertical fading when the pinned header is present
        // TODO change ListView to allow separate measures for top and bottom fading edge;
        // in this particular case we would like to disable the top, but not the bottom edge.
        if (mHeaderView != null) {
            setFadingEdgeLength(0);
        }
    }

    public void setIndexBarView(View indexBarView) {
        mIndexBarViewMargin = (int)mContext.getResources().getDimension(R.dimen.index_bar_view_margin);
        mIndexBarViewMarginTop=(int)mContext.getResources().getDimension(R.dimen.index_bar_view_margin2);
        this.mIndexBarView = indexBarView;
    }

    public void setPreviewView(View previewTextView) {
        this.mPreviewTextView=previewTextView;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        if (mHeaderView != null) {
            measureChild(mHeaderView, widthMeasureSpec, heightMeasureSpec);
            mHeaderViewWidth = mHeaderView.getMeasuredWidth();
            mHeaderViewHeight = mHeaderView.getMeasuredHeight();
        }  

        if (mIndexBarView != null && mIndexBarVisibility) {
            measureChild(mIndexBarView, widthMeasureSpec, heightMeasureSpec);
            mIndexBarViewWidth = mIndexBarView.getMeasuredWidth();
            mIndexBarViewHeight = mIndexBarView.getMeasuredHeight();
        } 

        if (mPreviewTextView != null && mPreviewVisibility) {
            measureChild(mPreviewTextView, widthMeasureSpec, heightMeasureSpec);
            mPreviewTextViewWidth = mPreviewTextView.getMeasuredWidth();
            mPreviewTextViewHeight = mPreviewTextView.getMeasuredHeight();
        }
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        if (mHeaderView != null) {
            mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
            configureHeaderView(getFirstVisiblePosition());
        }

        if (mIndexBarView != null && mIndexBarVisibility) {
            mIndexBarView.layout(getMeasuredWidth()- mIndexBarViewMargin - mIndexBarViewWidth, 0
                    , getMeasuredWidth()- mIndexBarViewMargin, getMeasuredHeight());

        }

        if (mPreviewTextView != null && mPreviewVisibility) {
            mPreviewTextView.layout(mIndexBarView.getLeft()-mPreviewTextViewWidth, (int)mIndexBarY-(mPreviewTextViewHeight/2)
                , mIndexBarView.getLeft(), (int)(mIndexBarY-(mPreviewTextViewHeight/2))+mPreviewTextViewHeight);
        }
    }

    public void setIndexBarVisibility(Boolean isVisible) {
        if(isVisible) {
            mIndexBarVisibility=true;
        }
        else {
            mIndexBarVisibility=false;
        }
    }

    private void setPreviewTextVisibility(Boolean isVisible) {
        if(isVisible) {
            mPreviewVisibility=true;
        }
        else {
            mPreviewVisibility=false;
        }
    }

    public void configureHeaderView(int position) {
        if (mHeaderView == null) {
            return;
        }

        int state = mAdapter.getPinnedHeaderState(position);

        switch (state) {

            case IPinnedHeader.PINNED_HEADER_GONE:
                mHeaderVisibility = false;
                break;
            case IPinnedHeader.PINNED_HEADER_VISIBLE:
                if (mHeaderView.getTop() != 0) {
                    mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
                }
                mAdapter.configurePinnedHeader(mHeaderView, position);
                mHeaderVisibility = true;
                break;
            case IPinnedHeader.PINNED_HEADER_PUSHED_UP:
                View firstView = getChildAt(0);
                int bottom = firstView.getBottom();
                // int itemHeight = firstView.getHeight();
                int headerHeight = mHeaderView.getHeight();
                int y;
                if (bottom < headerHeight) {
                    y = (bottom - headerHeight);
                }
                else {
                    y = 0;
                }

                if (mHeaderView.getTop() != y) {
                    mHeaderView.layout(0, y, mHeaderViewWidth, mHeaderViewHeight + y);
                }
                mAdapter.configurePinnedHeader(mHeaderView, position);
                mHeaderVisibility = true;
                break;
        }
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);// draw list view elements (zIndex == 1)

        if (mHeaderView != null && mHeaderVisibility) {
            drawChild(canvas, mHeaderView, getDrawingTime()); // draw pinned header view (zIndex == 2)
        }
        if (mIndexBarView != null && mIndexBarVisibility) {
            drawChild(canvas, mIndexBarView, getDrawingTime()); // draw index bar view (zIndex == 3)
        }
        if (mPreviewTextView != null && mPreviewVisibility) {
            drawChild(canvas, mPreviewTextView, getDrawingTime()); // draw preview text view (zIndex == 4)
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (mIndexBarView != null && ((IndexBarNoScrollView)mIndexBarView).onTouchEvent(ev)) {
            setPreviewTextVisibility(true);
            return true;
        }
        else {
            setPreviewTextVisibility(false);
            return super.onTouchEvent(ev);
        }
    }

    @Override
    public void filterList(float indexBarY, int position,String previewText) {
        this.mIndexBarY=indexBarY;

        if(mPreviewTextView instanceof TextView)
            ((TextView)mPreviewTextView).setText(previewText);

        setSelection(position);
    }
}

解决方案五:

这个跟onlayout没半毛钱关系,出错的是你的数据,如果我没猜错的话你的list里面存的都是null,也就是说你解析数据的时候就已经错了,看看自己的数据和数据的解析方法吧

解决方案六:

还有你解析错误的地方既然捕捉的异常你至少应该打印点啥,不应该就这么屏蔽掉

时间: 2024-09-27 00:38:37

安卓-adapter无法绑定数据,get(poiniton)无法获取到数据的相关文章

.net 获取 Json 数据 里面的数据

问题描述 这个是类似的json['LiveGame':{'TaskRoleSpaces':'选1','TaskRoles':'赛事1','ProxyUserID':'轮次1','UserID':'比赛时间1'},{'TaskRoleSpaces':'选2','TaskRoles':'赛事2','ProxyUserID':'轮次2','UserID':'比赛时间2'}],'Lottery':{'TaskRoleSpaces':'选1','TaskRoles':'赛事1','ProxyUserID'

Ajax获取到数据放入echarts里不显示的原因分析及解决办法_AJAX相关

在做一个需要用到echarts地图的项目的时候,成功通过ajax获取到了后台提供的数据,并生成了想要的JSON串.但是,放到echarts option.series[0].data里,获取不到数据.在生成的地图上无法看到你从后台获取到的值.翻遍百度和必应,给出的答案五花八门,仍旧未解决问题,最后还是一个同事大牛给解决的,在此分享给大家.希望对大家有帮助,,,, 废话不多说,直接上码: $(function () { var data = []; function setOption(data)

关于安卓开发时绑定按钮监听器老出错

问题描述 关于安卓开发时绑定按钮监听器老出错 不知道程序错在哪,一运行就出错?求哪位大神解答一下 解决方案 我照你的代码自己运行了下,然后没有问题, 你确认下你使用的listener是CompoundButton这个的 即看下你有没有导入这个包,是不是导错了.. import android.widget.CompoundButton.OnCheckedChangeListener; 解决方案二: 一个监听器绑定多个按钮控件 解决方案三: yjhvfkkllpp 解决方案四: 运行错误时是什么错

dataset-DataGridView绑定DataSet,如何每5行数据中间空一行,并且空行不要分格?

问题描述 DataGridView绑定DataSet,如何每5行数据中间空一行,并且空行不要分格? DataGridView绑定DataSet,如何每5行数据中间空一行,并且空行不要分格?请问怎么实现? 解决方案 不要直接绑定,这么写 int i = 1; forrach (var row in DataSet.Tables[0].Rows) { dgv.Rows.Add(new string[] { row["字段1"], row["字段2"], ... });

.Net程序员安卓学习之路4:使用xutils Get Post数据

原文:.Net程序员安卓学习之路4:使用xutils Get Post数据 前面使用了一些网络上找来的类进行网络访问,后来发现了安卓开发中有一个国人写的类库xutils比较全面,也比较经典,故后续使用xutils类库进行记录. 本例服务端使用WCF来实现,写好的WCF服务端在:http://www.cnblogs.com/madyina/p/3454741.html 下载部署即可 该服务说明如下: 这4个公开方法均返回一个User对象,其中最后一个还接收一个User对象. 下面我们就分别请求这4

TreeView绑定无限级分类问题(数据库读数据)

问题描述 如何实现TreeView绑定无限级分类,求源码! 解决方案 解决方案二:嵌套试试以前做DataList的时候,就是嵌套做到绑定父类下面子类的类似树状节点和TreeView原理是一样的解决方案三:privatevoidInitTree(TreeNodeCollectionNds,stringparentId){DataViewdv=newDataView();TreeNodetmpNd;stringintId;dv.Table=ds.Tables["tree"];dv.RowF

DEV控件中的ComboBoxEdit控件comboboxedit 绑定数据后 获取这数据的id

问题描述 comboboxedit绑定数据后获取这数据的id 解决方案 解决方案二: 解决方案三:英语太渣看不懂解决方案四:combobox只能获取EditValue,不知道你所谓的ID是什么意思.如果是数据中的一列,可以考虑使用Lookupedit,然后获取当前选择的行,再取id

android-在安卓中创建了一个小程序去获取联系人的姓名和电话号码,为什么会提示电话号码这一列不存在

问题描述 在安卓中创建了一个小程序去获取联系人的姓名和电话号码,为什么会提示电话号码这一列不存在 ListAdapter adapter = new SimpleCursorAdapter(this, //定义List中每一行的显示模板 //表示每一行包含两个数据项 android.R.layout.simple_list_item_2, //数据库的Cursor对象 cursor, //从数据库的Name额Number两列中取数据 new String [] {PhoneLookup.DISP

Scott Mitchell的ASP.NET 2.0数据教程之四:使用ObjectDataSource展现数据

返回"ASP.NET 2.0数据教程目录" 导言 在完成了应用程序架构和页面的设计后,我们可以开始探讨如何实现多种多样的普通数据到报表展现的任务.前面我们已经了 解到如何在从数据访问层和业务逻辑层绑定数据到ASP.NET页面上的数据控件.在ASP.NET 1.x应用程序中,通过对数据控件的DataSource属性 赋值然后调用控件的DataBind()方法从而实现数据展现的方式在ASP.NET 2.0应用程序中可以继续使用.然而,ASP.NET 2.0的数据源控件提供 了一种新的方式,