自定义列表视图使用光标,它应该显示图像为listitem

时间:2011-09-29 11:03:04

标签: android

我正在开发一个使用自定义列表视图的应用程序,listview由来自简单游标适配器的数据填充。现在我想将图像显示为listitem,并且每个列表项都有所不同。我的代码是:

dbHelper = new DatabaseHelper(this);
        try {
            String strDrSearchName = etSearchVisitDr.getText().toString();
            Cursor c = dbHelper.getViewAllDoctorSearch(strDrSearchName);
            Log.d("Search", "Search");
            startManagingCursor(c);
            from = new String[] {
                    DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, 
                    DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            to = new int[] {
                    R.id.txtDrCode, 
                    R.id.txtDrName, 
                    R.id.txtDrCat,
                    R.id.txtDrCity, 
                    R.id.txtDrSpec };
            SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
                    R.layout.gridvisitdoctor, c, from, to);
            list.setAdapter(sca);

它工作正常并在列表中显示结果但是如何将图像显示为列表项,这对于所有列表项都是不同的。

我解决了这个,这是我的代码

package pkg.ecpTablet;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.graphics.Color;
import android.graphics.Path.FillType;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class CurrentVisitDoctor extends Activity {

    Button btnToggleAP;
    Button btnDrVisitback;

    EditText etSearchDrVisit;

    ListView listDrCurrentVisit;

    TextView txtDate;
    TextView txtPlanned;
    TextView txtVisited;
    TextView txtTotal;

    DatabaseHelper dbHelper;
    String strDate;
    String strCTDay;

    ListView list;

    String[] from;
    int[] to;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.currentvisitdoctor);

        btnToggleAP = (Button) findViewById(R.id.btnToggleAP);
        btnDrVisitback = (Button) findViewById(R.id.btnDrVisitback);

        etSearchDrVisit = (EditText) findViewById(R.id.etSearchDrVisit);

        listDrCurrentVisit = (ListView) findViewById(R.id.listDrCurrentVisit);

        txtDate = (TextView) findViewById(R.id.txtDate);

        txtPlanned = (TextView) findViewById(R.id.txtPlanned);
        txtVisited = (TextView) findViewById(R.id.txtVisited);
        txtTotal = (TextView) findViewById(R.id.txtTotal);

        btnDrVisitback.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                Intent iBack = new Intent(CurrentVisitDoctor.this,
                        VisitHome.class);
                startActivity(iBack);

            }
        });

        // LoadGridTourPlanDr();
        fillDataTourPlannedDr();
        Bundle b = new Bundle();
        b = getIntent().getExtras();

        final int flag = b.getInt("flag");

        if (flag == 0) {

            strDate = b.getString("ydate");
            txtDate.setText(strDate);

        }
        if (flag == 1) {
            strDate = b.getString("date");
            txtDate.setText(strDate);
        }
        if (flag == 2) {
            strDate = b.getString("Date");
            txtDate.setText(strDate);
        }

        try {

            String strVisitDate = txtDate.getText().toString().trim();

            SimpleDateFormat dateFormatMessage = new SimpleDateFormat(
                    "dd/MM/yyyy");
            Date dtVisitDate = dateFormatMessage.parse(strVisitDate);

            SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
            String dtMsgDate = postFormater.format(dtVisitDate);

            // Toast.makeText(this,dtMsgDate, 30).show();

            int CountTourPlan = dbHelper.CountTourPlanDr(dtMsgDate);
            int CountTotalVisited = dbHelper.CountTotalVisited(dtMsgDate);
            int CountVisit = dbHelper.getTodayDoneVisitDr(dtMsgDate);

            txtPlanned.setText("Planned(" + CountTourPlan + ")");
            txtTotal.setText("Total(" + CountTotalVisited + ")");
            txtVisited.setText("Visit(" + CountVisit + ")");

            /*
             * txtPlanned.setText(CountTourPlan); txtTotal.setText(CountVisit);
             * txtVisited.setText(CountTotalVisited);
             */

        } catch (Exception e) {
            Alerts.ShowMessageAlert(CurrentVisitDoctor.this, "",
                    String.valueOf(e));
        }

        // Toast.makeText(CurrentVisitDoctor.this, String.valueOf(flag),
        // 30).show();
        btnToggleAP.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                etSearchDrVisit.setText("");

                if (btnToggleAP.getText().toString().equals("P")) {
                    btnToggleAP.setText("A");
                    // LoadGridAllDr();
                    fillDataAllDr();

                } else {
                    btnToggleAP.setText("P");
                    // LoadGridTourPlanDr();
                    fillDataTourPlannedDr();

                }

            }

        });

        etSearchDrVisit.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {
                if (btnToggleAP.getText().toString().equals("P")) {

                    LoadGridTourPlanDrSearch();
                } else {

                    // LoadGridAllDrSearch();
                    fillDataAllDrSearch();
                }

            }

            public void beforeTextChanged(CharSequence arg0, int arg1,
                    int arg2, int arg3) {
                if (btnToggleAP.getText().toString().equals("P")) {

                    // LoadGridTourPlanDrSearch();
                    fillDataTourPlannedDrSearch();
                } else {

                    // LoadGridAllDrSearch();
                    fillDataAllDrSearch();
                }

            }

            public void afterTextChanged(Editable arg0) {
                if (btnToggleAP.getText().toString().equals("P")) {

                    // LoadGridTourPlanDrSearch();
                    fillDataTourPlannedDrSearch();
                } else {

                    // LoadGridAllDrSearch();
                    fillDataAllDrSearch();
                }

            }
        });

        listDrCurrentVisit.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                // TODO Auto-generated method stub
                SQLiteCursor cr = (SQLiteCursor) parent
                        .getItemAtPosition(position);

                String DrName = cr.getString(cr
                        .getColumnIndex(DatabaseHelper.colvarDrName));
                String DrCode = cr.getString(cr
                        .getColumnIndex(DatabaseHelper.colvarDrCode));
                int intDrcode = Integer.parseInt(DrCode);
                int drGlCode = dbHelper.GetDrID(DrName);

                String DrCategory = cr.getString(cr
                        .getColumnIndex(DatabaseHelper.colvarCategory));
                String DrCityname = cr.getString(cr
                        .getColumnIndexOrThrow(DatabaseHelper.colvarCityName));

                String DrSpeciality = cr.getString(cr
                        .getColumnIndex(DatabaseHelper.colvarSpeciality));

                Bundle b = new Bundle();
                Intent deviatedvisits = new Intent(CurrentVisitDoctor.this,
                        DoctorVisit.class);
                b.putInt("drGlCode", drGlCode);
                b.putString("drname", DrName);
                b.putString("drcode", DrCode);
                b.putString("drspeciality", DrSpeciality);
                b.putString("drcity", DrCityname);
                b.putString("drcategory", DrCategory);
                b.putInt("flag", flag);

                b.putString("Date", txtDate.getText().toString());

                deviatedvisits.putExtras(b);
                startActivity(deviatedvisits);

            }
        });

    }

    public void LoadGridAllDr() {
        dbHelper = new DatabaseHelper(this);
        try {

            // Cursor c=dbHelper.getTourPlan();

            Cursor c = dbHelper.getViewAllDoctor();
            // Cursor
            // c=dbHelper.getViewAllDoctor(strDrSearchCode,strDrSearchName,strDrSearchCat,strDrSearchCity,strDrSearchSpec);
            startManagingCursor(c);

            // int no = Integer.valueOf((String.valueOf(cr.toString())));

            // txtVisitToday.setText(String.valueOf(cr.getColumnIndex("TodayPlan")));

            // txtVisitToday.setText(String.valueOf(c.getColumnCount()));
            String[] from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            int[] to = new int[] { R.id.txtDrCode, R.id.txtDrName,
                    R.id.txtDrCat, R.id.txtDrCity, R.id.txtDrSpec };
            SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(sca);
            // Toast.makeText(VisitDoctor.this,
            // String.valueOf(dbHelper.getTodayPlanDrVisit()),
            // Toast.LENGTH_LONG).show();

        } catch (Exception ex) {
            // AlertDialog.Builder b=new AlertDialog.Builder(this);
            // b.setMessage(ex.toString());
            // b.show();
        }
    }

    public void LoadGridTourPlanDr() {
        dbHelper = new DatabaseHelper(this);
        try {

            String strVisitDate = txtDate.getText().toString().trim();
            // Toast.makeText(CurrentVisitDoctor.this, strVisitDate, 30).show();

            SimpleDateFormat dateFormatMessage = new SimpleDateFormat(
                    "dd/MM/yyyy");
            Date dtVisitDate = dateFormatMessage.parse(strVisitDate);

            SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
            String dtMsgDate = postFormater.format(dtVisitDate);
            // Cursor c=dbHelper.getTourPlan();

            Cursor c = dbHelper.getViewPlanDoctor(dtMsgDate);
            // Cursor
            // c=dbHelper.getViewAllDoctor(strDrSearchCode,strDrSearchName,strDrSearchCat,strDrSearchCity,strDrSearchSpec);
            startManagingCursor(c);

            // int intTourPlanToday = dbHelper.getTodayPlanDrVisit();
            // int no = Integer.valueOf((String.valueOf(cr.toString())));

            // txtVisitToday.setText(String.valueOf(cr.getColumnIndex("TodayPlan")));

            // txtVisitToday.setText(String.valueOf(c.getColumnCount()));
            String[] from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            int[] to = new int[] { R.id.txtDrCode, R.id.txtDrName,
                    R.id.txtDrCat, R.id.txtDrCity, R.id.txtDrSpec };
            SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(sca);
            // Toast.makeText(VisitDoctor.this,
            // String.valueOf(dbHelper.getTodayPlanDrVisit()),
            // Toast.LENGTH_LONG).show();

        } catch (Exception ex) {
            // AlertDialog.Builder b=new AlertDialog.Builder(this);
            // b.setMessage(ex.toString());
            // b.show();
        }
    }

    public void LoadGridAllDrSearch() {
        dbHelper = new DatabaseHelper(this);
        try {

            String strDrSearchName = etSearchDrVisit.getText().toString();

            String strDrName = etSearchDrVisit.getText().toString();
            String finaleDrNameSearch = strDrName;
            Cursor c = dbHelper.getViewAllDoctorSearch(finaleDrNameSearch);

            // Cursor c=dbHelper.getViewAllDoctorSearch(strDrSearchCode,
            // strDrSearchName, strDrSearchCat, strDrSearchCity,
            // strDrSearchSpec);

            startManagingCursor(c);

            // int no = Integer.valueOf((String.valueOf(cr.toString())));

            // txtVisitToday.setText(String.valueOf(cr.getColumnIndex("TodayPlan")));

            // txtVisitToday.setText(String.valueOf(c.getColumnCount()));
            String[] from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            int[] to = new int[] { R.id.txtDrCode, R.id.txtDrName,
                    R.id.txtDrCat, R.id.txtDrCity, R.id.txtDrSpec };
            SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(sca);
            // Toast.makeText(VisitDoctor.this,
            // String.valueOf(dbHelper.getTodayPlanDrVisit()),
            // Toast.LENGTH_LONG).show();

        } catch (Exception ex) {
            AlertDialog.Builder b = new AlertDialog.Builder(this);
            b.setMessage(ex.toString());
            b.show();
        }
    }

    public void LoadGridTourPlanDrSearch() {
        dbHelper = new DatabaseHelper(this);
        try {

            String strVisitDate = txtDate.getText().toString().trim();

            SimpleDateFormat dateFormatMessage = new SimpleDateFormat(
                    "dd/MM/yyyy");
            Date dtVisitDate = dateFormatMessage.parse(strVisitDate);

            SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
            String dtMsgDate = postFormater.format(dtVisitDate);

            String strDrName = etSearchDrVisit.getText().toString();
            String finaleDrNameSearch = strDrName;
            Cursor c = dbHelper.getViewPlanDoctorSearch(finaleDrNameSearch,
                    dtMsgDate);

            // Cursor c=dbHelper.getViewPlanDoctorSearch(strDrSearchCode,
            // strDrSearchName, strDrSearchCat, strDrSearchCity,
            // strDrSearchSpec);

            startManagingCursor(c);

            // int no = Integer.valueOf((String.valueOf(cr.toString())));

            // txtVisitToday.setText(String.valueOf(cr.getColumnIndex("TodayPlan")));

            // txtVisitToday.setText(String.valueOf(c.getColumnCount()));
            String[] from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            int[] to = new int[] { R.id.txtDrCode, R.id.txtDrName,
                    R.id.txtDrCat, R.id.txtDrCity, R.id.txtDrSpec };
            SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(sca);
            // Toast.makeText(VisitDoctor.this,
            // String.valueOf(dbHelper.getTodayPlanDrVisit()),
            // Toast.LENGTH_LONG).show();

        } catch (Exception ex) {
            AlertDialog.Builder b = new AlertDialog.Builder(this);
            b.setMessage(ex.toString());
            b.show();
        }
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();

        btnToggleAP = (Button) findViewById(R.id.btnToggleAP);
        btnDrVisitback = (Button) findViewById(R.id.btnDrVisitback);

        etSearchDrVisit = (EditText) findViewById(R.id.etSearchDrVisit);

        listDrCurrentVisit = (ListView) findViewById(R.id.listDrCurrentVisit);

        txtDate = (TextView) findViewById(R.id.txtDate);

        // LoadGridTourPlanDr();
        fillDataTourPlannedDr();
        Bundle b = new Bundle();
        b = getIntent().getExtras();

        final int flag = b.getInt("flag");

        if (flag == 0) {

            strDate = b.getString("ydate");
            txtDate.setText(strDate);

        }
        if (flag == 1) {
            strDate = b.getString("date");
            txtDate.setText(strDate);
        }
        if (flag == 2) {
            strDate = b.getString("Date");
            txtDate.setText(strDate);
        }
    }

    protected void fillDataAllDr() {

        dbHelper = new DatabaseHelper(this);

        Cursor c = dbHelper.getViewAllDoctor();
        startManagingCursor(c);

        from = new String[] { DatabaseHelper.colvarDrCode,
                DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                DatabaseHelper.colvarCityName, DatabaseHelper.colvarSpeciality };
        to = new int[] { R.id.txtDrCode, R.id.txtDrName, R.id.txtDrCat,
                R.id.txtDrCity, R.id.txtDrSpec };
        // SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
        // R.layout.gridvisitdoctor, c, from, to);

        customCursorAdapter cca = new customCursorAdapter(this,
                R.layout.gridvisitdoctor, c, from, to);
        listDrCurrentVisit.setAdapter(cca);
    }

    protected void fillDataTourPlannedDr() {

        dbHelper = new DatabaseHelper(this);
        try {
            // Cursor c = dbHelper.getViewAllDoctor();
            // startManagingCursor(c);

            String strVisitDate = txtDate.getText().toString().trim();
            // Toast.makeText(CurrentVisitDoctor.this, strVisitDate, 30).show();

            SimpleDateFormat dateFormatMessage = new SimpleDateFormat(
                    "dd/MM/yyyy");
            Date dtVisitDate = dateFormatMessage.parse(strVisitDate);

            SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
            String dtMsgDate = postFormater.format(dtVisitDate);
            // Cursor c=dbHelper.getTourPlan();

            Cursor c = dbHelper.getViewPlanDoctor(dtMsgDate);
            // Cursor
            // c=dbHelper.getViewAllDoctor(strDrSearchCode,strDrSearchName,strDrSearchCat,strDrSearchCity,strDrSearchSpec);
            startManagingCursor(c);

            // int intTourPlanToday = dbHelper.getTodayPlanDrVisit();

            from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            to = new int[] { R.id.txtDrCode, R.id.txtDrName, R.id.txtDrCat,
                    R.id.txtDrCity, R.id.txtDrSpec };
            // SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
            // R.layout.gridvisitdoctor, c, from, to);

            customCursorAdapter cca = new customCursorAdapter(this,
                    R.layout.gridvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(cca);
        } catch (Exception ex) {
            // AlertDialog.Builder b=new AlertDialog.Builder(this);
            // b.setMessage(ex.toString());
            // b.show();
        }

    }

    protected void fillDataAllDrSearch() {

        dbHelper = new DatabaseHelper(this);
        try {

            String strDrSearchName = etSearchDrVisit.getText().toString();

            String strDrName = etSearchDrVisit.getText().toString();
            String finaleDrNameSearch = strDrName;
            Cursor c = dbHelper.getViewAllDoctorSearch(finaleDrNameSearch);

            // Cursor c=dbHelper.getViewAllDoctorSearch(strDrSearchCode,
            // strDrSearchName, strDrSearchCat, strDrSearchCity,
            // strDrSearchSpec);

            startManagingCursor(c);
            // Cursor c = dbHelper.getViewAllDoctor();
            // startManagingCursor(c);

            from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            to = new int[] { R.id.txtDrCode, R.id.txtDrName, R.id.txtDrCat,
                    R.id.txtDrCity, R.id.txtDrSpec };
            // SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
            // R.layout.gridvisitdoctor, c, from, to);

            customCursorAdapter cca = new customCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(cca);
        } catch (Exception ex) {
            AlertDialog.Builder b = new AlertDialog.Builder(this);
            b.setMessage(ex.toString());
            b.show();
        }

    }

    protected void fillDataTourPlannedDrSearch() {

        dbHelper = new DatabaseHelper(this);
        try {

            String strVisitDate = txtDate.getText().toString().trim();

            SimpleDateFormat dateFormatMessage = new SimpleDateFormat(
                    "dd/MM/yyyy");
            Date dtVisitDate = dateFormatMessage.parse(strVisitDate);

            SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd");
            String dtMsgDate = postFormater.format(dtVisitDate);

            String strDrName = etSearchDrVisit.getText().toString();
            String finaleDrNameSearch = strDrName;
            Cursor c = dbHelper.getViewPlanDoctorSearch(finaleDrNameSearch,
                    dtMsgDate);

            // Cursor c=dbHelper.getViewPlanDoctorSearch(strDrSearchCode,
            // strDrSearchName, strDrSearchCat, strDrSearchCity,
            // strDrSearchSpec);

            startManagingCursor(c);

            // int intTourPlanToday = dbHelper.getTodayPlanDrVisit();

            from = new String[] { DatabaseHelper.colvarDrCode,
                    DatabaseHelper.colvarDrName, DatabaseHelper.colvarCategory,
                    DatabaseHelper.colvarCityName,
                    DatabaseHelper.colvarSpeciality };
            to = new int[] { R.id.txtDrCode, R.id.txtDrName, R.id.txtDrCat,
                    R.id.txtDrCity, R.id.txtDrSpec };
            // SimpleCursorAdapter sca = new SimpleCursorAdapter(this,
            // R.layout.gridvisitdoctor, c, from, to);

            customCursorAdapter cca = new customCursorAdapter(this,
                    R.layout.gridcurrentvisitdoctor, c, from, to);
            listDrCurrentVisit.setAdapter(cca);
        } catch (Exception ex) {
            // AlertDialog.Builder b=new AlertDialog.Builder(this);
            // b.setMessage(ex.toString());
            // b.show();
        }

    }

} // class complete

// ListView Adapter Class

class customCursorAdapter extends SimpleCursorAdapter {
    private int layout;
    Context context;

    public customCursorAdapter(Context context, int layout, Cursor cursor,
            String[] from, int[] to) {
        super(context, layout, cursor, from, to);
        this.layout = layout;
        this.context = context;

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ViewHolder holder;
        int flag = 1;
        if (view != null) {
            holder = new ViewHolder();
            holder.txtViewDrname = (TextView) view.findViewById(R.id.txtDrName);
            holder.txtViewDrCode = (TextView) view.findViewById(R.id.txtDrCode);
            holder.txtViewDrSpec = (TextView) view.findViewById(R.id.txtDrSpec);
            holder.txtViewDrCity = (TextView) view.findViewById(R.id.txtDrCity);
            holder.txtViewDrCat = (TextView) view.findViewById(R.id.txtDrCat);
            holder.imgbullet = (ImageView) view.findViewById(R.id.imgVisited);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        String DrName = cursor.getString(cursor
                .getColumnIndex(DatabaseHelper.colvarDrName));
        // String name = cursor.;

        if (holder.txtViewDrname != null) {
            holder.txtViewDrname.setText(DrName);
            holder.txtViewDrname.setTextColor(Color.RED);
        }

        String DrCode = cursor.getString(cursor
                .getColumnIndex(DatabaseHelper.colvarDrCode));
        holder.txtViewDrCode.setText(DrCode);

        String DrSpeciality = cursor.getString(cursor
                .getColumnIndex(DatabaseHelper.colvarSpeciality));
        holder.txtViewDrSpec.setText(DrSpeciality);

        String DrCityName = cursor.getString(cursor
                .getColumnIndex(DatabaseHelper.colvarCityName));
        holder.txtViewDrCity.setText(DrCityName);

        String DrCategory = cursor.getString(cursor
                .getColumnIndex(DatabaseHelper.colvarCategory));
        holder.txtViewDrCat.setText(DrCategory);

        if (DrName.equals("A. B. Mehta")) {
            holder.imgbullet.setBackgroundResource(R.drawable.yellow_bulet);
        }
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {

        LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(layout, parent, false);

        return view;
    }

    @Override
    public long getItemId(int id) {
        return id;
    }

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

}

class ViewHolder {
    TextView txtViewDrname;
    TextView txtViewDrCode;
    TextView txtViewDrCity;
    TextView txtViewDrSpec;
    TextView txtViewDrCat;
    ImageView imgbullet;

}

0 个答案:

没有答案