0

パラメータに基づいてリストビューの背景行の色を変更しようとしていますが、View v = super.getView(position, convertView, parent)その行で「アダプタ型の抽象メソッド getView(int, View, ViewGroup) を直接呼び出すことはできません」というエラーが表示されます。これがすべてのコードです。

public class CustomListViewAdapter extends BaseAdapter
{  

LayoutInflater inflater;
List<ListViewItem> items;

public CustomListViewAdapter(Activity context, List<ListViewItem> items) {  
    super();

    this.items = items;
    this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override  
public int getCount() {  
    // TODO Auto-generated method stub  
    return items.size();  
}  

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

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

@Override  
public View getView(final int position, View convertView, ViewGroup parent) {  
    View v = super.getView(position, convertView, parent); 

    ListViewItem item = items.get(position);

    if(convertView==null)
        v = inflater.inflate(R.layout.my_hospitals, null);
        TextView status = (TextView) v.findViewById(R.id.status);
        TextView name = (TextView) v.findViewById(R.id.name);
        TextView table = (TextView) v.findViewById(R.id.id);
        TextView info = (TextView) v.findViewById(R.id.info);

        status.setText(item.status);
        name.setText(item.name);
        table.setText(item.table);
        info.setText(item.info);

        if (item.status == "green"){
            v.setBackgroundColor(Color.GREEN);
        }

    return v;  
}
}
4

3 に答える 3

1

getView() を変更

@Override  
public View getView(final int position, View convertView, ViewGroup parent) {  
    View v=convertView;
    ListViewItem item = items.get(position);

    if(v==null){
        v = inflater.inflate(R.layout.my_hospitals, null);
    }
        TextView status = (TextView) v.findViewById(R.id.status);
        TextView name = (TextView) v.findViewById(R.id.name);
        TextView table = (TextView) v.findViewById(R.id.id);
        TextView info = (TextView) v.findViewById(R.id.info);

        status.setText(item.status);
        name.setText(item.name);
        table.setText(item.table);
        info.setText(item.info);     
        String state=tem.status;


        if (state.equals("green"){
            v.setBackgroundColor(Color.GREEN);
        }

    return v;  
}
于 2013-11-11T16:42:31.227 に答える
0

多分私はあなたの質問をよく理解していませんでしたが、これの代わりに

item.status == "green"

これを使って

item.status.equals("緑")

于 2013-11-11T16:42:02.447 に答える