0

私の活動クラス

public class BRActivityList extends Activity {
private UserDBAdapter dbHelper;
ListView list;
MyListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bractivitylist);
    dbHelper=new UserDBAdapter(this);
    displayBRActivityList();
}
private void displayBRActivityList()
{
    ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String, String>>();
    dbHelper.open();
    Cursor cursor=dbHelper.fetchAllData();
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put(LoginDatabaseOpenHelper.COLUMN_CONSUMERNAME, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_CONSUMERNAME)));
        map.put(LoginDatabaseOpenHelper.COLUMN_AGE, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_AGE)));
        map.put(LoginDatabaseOpenHelper.COLUMN_MOBILE, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_MOBILE)));
        map.put(LoginDatabaseOpenHelper.COLUMN_DIST, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_DIST)));
        map.put(LoginDatabaseOpenHelper.COLUMN_BRAND, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_BRAND)));
        map.put(LoginDatabaseOpenHelper.COLUMN_DOB, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_DOB)));
        map.put(LoginDatabaseOpenHelper.COLUMN_AGRIMG, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_AGRIMG)));
        map.put(LoginDatabaseOpenHelper.COLUMN_SIGNATURE, cursor.getString(cursor.getColumnIndex(LoginDatabaseOpenHelper.COLUMN_SIGNATURE)));
        dataList.add(map);
      cursor.moveToNext();
    }
 // Make sure to close the cursor
    cursor.close();
    dbHelper.close();
    list=(ListView)findViewById(R.id.list);     
    list.setAdapter(new MyListAdapter(this, dataList));
}

}

私のアダプタークラス

public class MyListAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
private AlbumStorageDirFactory mAlbumStorageDirFactory = null;

public MyListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
}


public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}


public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}


public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return 0;
}


public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView consumername = (TextView)vi.findViewById(R.id.consumername); // title
    TextView consumerage = (TextView)vi.findViewById(R.id.consumerage); // artist name
    TextView consumermob = (TextView)vi.findViewById(R.id.consumermob); // duration
    TextView consumerdist=(TextView)vi.findViewById(R.id.consumerdist);
    TextView consumerdob=(TextView)vi.findViewById(R.id.consumerdob);
    TextView brand=(TextView)vi.findViewById(R.id.brand);
    ImageView consumerimg=(ImageView)vi.findViewById(R.id.list_image); // thumb image

    HashMap<String, String> consumerdata = new HashMap<String, String>();
    consumerdata = data.get(position);

    // Setting all values in listview
    consumername.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_CONSUMERNAME));
    consumerage.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_AGE));
    consumermob.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_MOBILE));
    consumerdist.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_DIST));
    consumerdob.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_DOB));
    brand.setText(consumerdata.get(LoginDatabaseOpenHelper.COLUMN_BRAND));
    Resources res = activity.getResources();
    consumerimg.setImageDrawable(res.getDrawable(R.drawable.rihanna));
    return vi;
}
}

私はそれを数回デバッグしますが、getView メソッドを呼び出すことはありません。何が問題なのかを特定できません。コードの何が問題なのか。

4

1 に答える 1

4
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

getCount()データセット内のエントリ数を返す必要があります。次のように変更します。

public int getCount() {
    // TODO Auto-generated method stub
    return (data == null) ? 0 : data.size();
}
于 2013-07-03T13:22:01.760 に答える