18

BindView does not start, then listview blank

 4 years ago
source link: https://www.codesd.com/item/bindview-does-not-start-then-listview-blank.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

BindView does not start, then listview blank

advertisements

I have a custom cursor adaptor which seems to be mostly working, except for the bindView method. I have Log calls inside bindView which are never appearing in my logCat. The listView I create is being displayed with the correct number of rows but the rows are blank. The onCLickListener is also working fine and logcat shows it has read rows from the database.

Code is as follows - in my activity:

// build a listView adapter
        Log.i(LOGTAG,"About to create listView...");
        tripList = (ListView) findViewById(android.R.id.list);
        //tripList = getListView();
        Log.i(LOGTAG,"ListView created...");

        Log.i(LOGTAG,"About to create adapter...");
        tripAdapter = new tripListAdapter(this, tripCur);
        //setListAdapter(tripAdapter);
        tripList.setAdapter(tripAdapter);

        tripList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                // Do something in response to the click
                // Enable other buttons
                togBtns(true);

                // set global variable to show which ID was clicked on
                listTripPosClicked = position;

                // Get details from display, of clicked item
                TextView tmpDate = (TextView) tripList.findViewById(R.id.dateFld);
                TextView tmpDist = (TextView) tripList.findViewById(R.id.distFld);
                TextView tmpMPG = (TextView) tripList.findViewById(R.id.mpgFld);

                // store these for sending to doTripActivity
                clickedDist = tmpDist.getText().toString();
                clickedDate = tmpDate.getText().toString();
                clickedMPG = tmpMPG.getText().toString();

                Log.i(LOGTAG, "Dist = " + clickedDist);
                Log.i(LOGTAG, "Date = " + clickedDate);
                Log.i(LOGTAG, "mpg = " + clickedMPG);

            }
        });

Adaptor code is:

// custom list adaptor class
private class tripListAdapter extends CursorAdapter {

    //private final Cursor dataC;
    private final LayoutInflater vi;
    public View theView;

    public tripListAdapter(Context con, Cursor c) {
        // super constructor thingy
        super(con, c);
        //dataC = c;
        vi = LayoutInflater.from(con);

    }

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

        Log.i(LOGTAG,"In getView...");
        // Create a message handling object as an anonymous class.
        //mTripClickHandler = new OnItemClickListener() {
        v = vi.inflate(R.layout.trip_row, parent, false);

        Log.i(LOGTAG,"Leaving getView...");
        return v;
    }

    @Override
    public void bindView(View v, Context arg1, Cursor dataC) {
        Log.i(LOGTAG,"In bindView...");
        // get data from cursor
        TextView dateTV = (TextView) v.findViewById(R.id.dateFld);
        TextView distTV = (TextView) v.findViewById(R.id.distFld);
        TextView mpgTV = (TextView) v.findViewById(R.id.mpgFld);

        String tmpMPG = dataC.getString(dataC.getColumnIndexOrThrow(dbHistory.TRIP_MPG));
        Double tmpNum = Double.valueOf(tmpMPG);
        tmpMPG = String.format("%.2f", tmpNum);

        dateTV.setText(dataC.getString(dataC.getColumnIndexOrThrow(dbHistory.TRIP_DATE)));
        distTV.setText(dataC.getString(dataC.getColumnIndexOrThrow(dbHistory.TRIP_MILES)));
        mpgTV.setText(tmpMPG);                      

        Log.i(LOGTAG,"Leaving bindView...");
    }

    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        Log.i(LOGTAG,"In newView...");
        //theView = vi.inflate(R.layout.trip_row, arg2, false);

        Log.i(LOGTAG,"Leaving newView...");
        return theView;
    }
}

Output from logCat shows the various Log messages but nothing from bindView, which I guess is why my listView is blank.

06-17 06:40:31.827: I/WIBBLE(866): About to create listView...
06-17 06:40:31.827: I/WIBBLE(866): ListView created...
06-17 06:40:31.838: I/WIBBLE(866): About to create adapter...
06-17 06:40:31.838: I/WIBBLE(866): OnResume with this many rows returned by cursor: 3
06-17 06:40:31.838: I/WIBBLE(866): In the loop, so cursor is not null....
06-17 06:40:31.897: I/WIBBLE(866): In getView...
06-17 06:40:31.917: I/WIBBLE(866): Leaving getView...
06-17 06:40:31.917: I/WIBBLE(866): In getView...
06-17 06:40:31.937: I/WIBBLE(866): Leaving getView...
06-17 06:40:31.957: I/WIBBLE(866): In getView...
06-17 06:40:31.967: I/WIBBLE(866): Leaving getView...
06-17 06:40:32.137: I/WIBBLE(866): In getView...
06-17 06:40:32.217: I/WIBBLE(866): Leaving getView...
06-17 06:40:32.279: I/WIBBLE(866): In getView...
06-17 06:40:32.347: I/WIBBLE(866): Leaving getView...
06-17 06:40:32.417: I/WIBBLE(866): In getView...
06-17 06:40:32.427: I/WIBBLE(866): Leaving getView...
06-17 06:40:32.959: I/Choreographer(866): Skipped 116 frames!  The application may be doing too much work on its main thread.
06-17 06:40:34.056: I/WIBBLE(866): In getView...
06-17 06:40:34.147: I/WIBBLE(866): Leaving getView...
06-17 06:40:34.197: I/WIBBLE(866): In getView...
06-17 06:40:34.267: I/WIBBLE(866): Leaving getView...
06-17 06:40:34.289: I/WIBBLE(866): In getView...
06-17 06:40:34.308: I/WIBBLE(866): Leaving getView...
06-17 06:40:39.486: I/WIBBLE(866): Dist =
06-17 06:40:39.486: I/WIBBLE(866): Date =
06-17 06:40:39.496: I/WIBBLE(866): mpg =

Any ideas why?


For Cursor based adapters the getView() method is implemented to call the newView() and bindView() methods. If you override it like you did, without calling super() those methods will not be called. So, remove the overridden getView() method and inflate the row layout in the newView() method.

Also, for Cursor based adapter you generally don't override the getView() method, you work with its two delegate methods that you need to override.


Recommend

  • 127
    • 掘金 juejin.im 7 years ago
    • Cache

    危险的 target="_blank" 与 “opener”

    在网页中使用链接时,如果想要让浏览器自动在新的标签页打开指定的地址,通常的做法就是在 a 标签上添加 target等于"_blank" 属性。 然而,就是这个属性,为钓鱼攻击者带来了可乘之机。 起源 parent 与 opener 在说 opener 之前,

  • 12

    start a new activity from each selected listView element advertisements I have a dialog fragment listView,on this list is a image and a textview.

  • 11

    Android ListView with Button is not selectable (Clickable) advertisements I am facing a strange problem, I have added a Custom row in my ListV...

  • 10

    通过反射和annotationProcessor来实现BindView ButterKnife相信大家都用过,哪怕没用过至少也应该都听说过。虽然官网已经表示deprecated,但是不影响我们对它的学习。记得刚开始使用的时候觉得这东西好神奇呀,减少了太多的代码,后来用熟了之后开始捣...

  • 4

    ListView's OnItemSelectedListener is not invoked advertisements I have a list view and using two listeners - OnItemClicked...

  • 10

    from the book “Hell Yeah or No”: If you’re not feeling “hell yeah!” then say no 2018-06-03 Most of us have lives filled with mediocrity. We said yes to things that we felt h...

  • 10
    • rachelbythebay.com 2 years ago
    • Cache

    Getting it or not getting it, and then what?

    Getting it or not getting it, and then what? I've been pondering a hypothesis for a while now. It has to do with the way that groups of people cluster together, particularly when certain topics are involved. This is a simplification...

  • 2
    • webdesign.tutsplus.com 2 years ago
    • Cache

    How to Start With a Blank Design in WordPress

    How to Start With a Blank Design in WordPress A blank design allows us to start afresh and customize our website to fit our exact needs and preferences. Starting from scratch gives us more control over the design and layout of our w...

  • 4

    Main is usually a function. So then when is it not? Jan 26, 2015 It began when my coworker, despite already knowing how to program, was forced to take the intro level Computer Science course at...

  • 4

    If digital transformation is not a destination, then what is it?Exploring the complex layers of digital transformation to understand why it’s an ‘ongoing process’.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK