Error in arrayadapter



朋友们,请帮帮我。这个程序出了什么问题。我不能在这里使用布局充气器。如何解决这个问题。

public class MyListAdapter extends ArrayAdapter<MyData> implements
        OnClickListener {
    private ArrayList<MyData> items;
    Context context;
    public MyListAdapter(Context context, int textViewResourceId,
            ArrayList<MyData> items) {
        super(context, textViewResourceId, items);
        this.items = items;
        this.context = context;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }
        MyData myData = items.get(position);
        if (myData != null) {
            TextView textViewTwo = (TextView) v
                    .findViewById(R.id.text_view_two);
            if (textViewTwo != null) {
                textViewTwo.setText(myData.getText());
                // put the id to identify the item clicked
                textViewTwo.setTag(myData.getId());
                textViewTwo.setOnClickListener(this);
            }
        }
        return v;
    }
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Log.d("Sample", "Clicked on tag: " + v.getTag());
        Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
    }
}

错误为:未定义类型MyListAdapter的方法getSystemService(String)。

提前谢谢。

使用

LayoutInflater vi = (LayoutInflater)
                      context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

而不是

LayoutInflater vi = (LayoutInflater) 
                  getSystemService(Context.LAYOUT_INFLATER_SERVICE);

因为对于CCD_ 1是Context类的方法而不是CCD_。u将需要使用上下文实例来访问getSystemService方法

像这个一样尝试context.getStystemService()

 LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

使用活动的上下文获取系统服务

这是给充气机打电话的正确方式。

Layout充气器vi=(Layout充气器)上下文getSystemService(Context.LAYOUT_INFLATER_SERVICE);

最新更新