自定义simpleCursorAdapter中的getLayoutInflater

Gre*_*reg 7 layout android adapter

我坚持创建自定义适配器.我想setOnClickListener里面的ListView的按钮,我发现这个题目看起来确定如何对setonclicklistener -上的按钮,里面最列表视图,但问题是,我在getLayoutInflater线越来越无法访问的代码错误.

这是我的代码

public class MyCursorAdapter extends SimpleCursorAdapter{

    private final Context ctx;
    private Button tagButton = null;

    public MyCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        ctx = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return super.getView(position, convertView, parent);
        LayoutInflater li = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = li.inflate(R.layout.tags_list_element, null, true);
        tagButton= (Button)rowView.findViewById(R.id.tag_title);
        tagButton.setTag(position);

        tagButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
            }
        });
        return rowView;

    }

}
Run Code Online (Sandbox Code Playgroud)

这两种方法对我都不起作用

  LayoutInflater inflater = context.getLayoutInflater();
Run Code Online (Sandbox Code Playgroud)

LayoutInflater li = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Run Code Online (Sandbox Code Playgroud)

Jej*_*dou 15

尝试:

View myView = LayoutInflater.from(ctx).inflate(R.layout.my_view, null);
Run Code Online (Sandbox Code Playgroud)

而且,你得到什么例外?


编辑:在你的"getView"方法中,第一行是"return .....",所以你的方法的其余部分将永远不会被执行,我想......;)