13

BindView does not start, then listview blank

 3 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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK