列表视图适配器在自定义对话框上设置空对象

mine

嗨,朋友们,我尝试在自定义对话框中实现列表视图,并通过使用JSON动态传递数据并在所有位置进行搜索,但是没有任何解决方案,我尝试了过去三天的所有尝试,并且我在代码中也没有看到任何错误我也已经正确设置了适配器,但出现此错误

尝试在空对象引用上调用虚拟方法'void android.widget.ListView.setAdapter(android.widget.ListAdapter)'

public class Cat_comment_adap extends BaseAdapter {

    String cid;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();
    int idddget;
    private LayoutInflater inflater;
    private List<CurrentList> catlist;
    private PopupWindow commentWindow;
    ArrayList<CurrentList> commentlist = new ArrayList<CurrentList>();

Activity activity;
    public Cat_comment_adap(Activity activity, List<CurrentList> catlist) {
        this.activity = activity;
        this.catlist = catlist;


    }

    @Override
    public int getCount() {
        return catlist.size();
    }

    @Override
    public Object getItem(int i) {
        return catlist.get(i);
    }

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

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.cat_row, viewGroup, false);


        NetworkImageView singleimg = (NetworkImageView) view.findViewById(R.id.singleimg);
        final ImageView agree = (ImageView) view.findViewById(R.id.agree);
        ImageView commentbox = (ImageView) view.findViewById(R.id.commentbox);
        commentbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onShowpopup(view);
                Toast.makeText(activity, "Comments Button clicked", Toast.LENGTH_SHORT).show();
            }
        });

        final CurrentList catertlist = catlist.get(i);

        singleimg.setImageUrl(catertlist.getCatimg(), imageLoader);

        idddget = catertlist.getCcids();
        SharedPreferences eveid = activity.getSharedPreferences("loginPrefs", Context.MODE_PRIVATE);
        cid = eveid.getString("userid", "");

        agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = "http://sampletemplates.net/majority/api.php?action=addVote&question_id=" + idddget + "&user_id=" + cid + "&vote=1&source=android";
                Log.d("Vote", "http://sampletemplates.net/majority/api.php?action=addVote&question_id=" + idddget + "&user_id=" + cid + "&vote=1&source=android");
                JsonObjectRequest voting = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            String votings = response.getString("status");
                            if (votings.equals("success")) {
                                agree.setImageResource(R.drawable.agreed);
                                Toast.makeText(activity, "Voted Successfully", Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(activity, "Already Voted", Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                });
                AppController.getInstance().addToRequestQueue(voting);
            }
        });
        return view;
    }

    public void onShowpopup(View v) {
        LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View popupview = layoutInflater.inflate(R.layout.current_comment_dialog, null);
        ListView commentsListView = (ListView) v.findViewById(R.id.commentsListView);
//        commentAdapter = new comment_adapter(activity, commentlist);
        WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;
        commentWindow = new PopupWindow(popupview, width - 50, height - 400, true);
        commentWindow.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.comment_bg));
        commentWindow.setFocusable(true);
        commentWindow.setOutsideTouchable(true);
        commentWindow.showAtLocation(v, Gravity.BOTTOM, 0, 100);
        commentsListView.setAdapter(new comment_adapter(activity,commentlist));
        commentAdapter.notifyDataSetChanged();
    }

转接器类别

public class comment_adapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private List<CurrentList> commentlist;
    public comment_adapter(Activity activity, List<CurrentList> commentlist){
        this.activity = activity;
        this.commentlist = commentlist;

    }

    @Override
    public int getCount() {
        return commentlist.size();
    }

    @Override
    public Object getItem(int i) {
        return commentlist.get(i);
    }

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

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (inflater == null)
            inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null)
            view = inflater.inflate(R.layout.comment_row, viewGroup, false);
        TextView user_name = (TextView) view.findViewById(R.id.user_name);
        TextView posttime = (TextView) view.findViewById(R.id.posttime);
        TextView comtsdetails = (TextView) view.findViewById(R.id.comtsdetails);
        CurrentList listofcomments = commentlist.get(i);
        user_name.setText(listofcomments.getEvtusername());
        posttime.setText(listofcomments.getTimetaken());
        comtsdetails.setText(listofcomments.getEvcomment());
        return view;
    }
}
阿尤布·巴巴(Ayub Baba)

这是在此类Cat_comment_adap中的onShowpopup方法中的更改view popupview = layoutInflater.inflate(R.layout.current_comment_dialog,null); ListView commentsListView =(ListView)v.findViewById(R.id.commentsListView);

查看popupview = layoutInflater.inflate(R.layout.current_comment_dialog,null); ListView commentsListView =(ListView)popupview.findViewById(R.id.commentsListView);

因为您从此布局中获取的膨胀listview,所以您必须在其中给出膨胀的布局对象的名称,而不是方法的参数

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在对话框片段和自定义列表视图适配器之间实现接口时出错

来自分类Dev

自定义适配器不显示列表视图

来自分类Dev

自定义旋转适配器显示空列表

来自分类Dev

如何通过自定义适配器为列表视图动态设置imageView源?

来自分类Dev

在自定义对话框中添加ViewPager。无法使适配器工作

来自分类Dev

从Android中的ListView适配器启动自定义警报对话框

来自分类Dev

从Android中的ListView适配器启动自定义警报对话框

来自分类Dev

在对话框中为列表视图设置适配器时发生NullpointerException

来自分类Dev

如何使用Hashmap为自定义列表视图创建自定义适配器

来自分类Dev

在片段中每个列表视图有多个文本视图的情况下,如何设置自定义适配器

来自分类Dev

与自定义适配器的警报对话

来自分类Dev

使用自定义适配器和视图持有器的Android列表视图

来自分类Dev

自定义文本视图适配器不适用于列表视图

来自分类Dev

使用自定义适配器视图时,如何使列表视图可点击?

来自分类Dev

在自定义列表视图适配器中使用多个视图

来自分类Dev

将列表视图的数据从Asynctask传递到自定义列表适配器类

来自分类Dev

列表视图中的页脚按钮,如何从自定义列表适配器获取价值

来自分类Dev

自定义对话框上的视图未显示

来自分类Dev

自定义对话框上的视图未显示

来自分类Dev

自定义视图的适配器中的NullPointerException

来自分类Dev

自定义适配器视图(带有图片)

来自分类Dev

自定义列表适配器onClick方法返回空视图ID

来自分类Dev

在自定义可扩展列表适配器中无法充实视图

来自分类Dev

Android过滤器列表视图自定义适配器

来自分类Dev

在自定义适配器列表视图中突出显示搜索到的文本

来自分类Dev

使用外部XML文件进行自定义列表视图适配器?

来自分类Dev

自定义适配器不会使列表视图中的行膨胀

来自分类Dev

在自定义适配器的列表视图项中加载不同的图像

来自分类Dev

我无法使用自定义适配器数据清除列表视图?

Related 相关文章

  1. 1

    在对话框片段和自定义列表视图适配器之间实现接口时出错

  2. 2

    自定义适配器不显示列表视图

  3. 3

    自定义旋转适配器显示空列表

  4. 4

    如何通过自定义适配器为列表视图动态设置imageView源?

  5. 5

    在自定义对话框中添加ViewPager。无法使适配器工作

  6. 6

    从Android中的ListView适配器启动自定义警报对话框

  7. 7

    从Android中的ListView适配器启动自定义警报对话框

  8. 8

    在对话框中为列表视图设置适配器时发生NullpointerException

  9. 9

    如何使用Hashmap为自定义列表视图创建自定义适配器

  10. 10

    在片段中每个列表视图有多个文本视图的情况下,如何设置自定义适配器

  11. 11

    与自定义适配器的警报对话

  12. 12

    使用自定义适配器和视图持有器的Android列表视图

  13. 13

    自定义文本视图适配器不适用于列表视图

  14. 14

    使用自定义适配器视图时,如何使列表视图可点击?

  15. 15

    在自定义列表视图适配器中使用多个视图

  16. 16

    将列表视图的数据从Asynctask传递到自定义列表适配器类

  17. 17

    列表视图中的页脚按钮,如何从自定义列表适配器获取价值

  18. 18

    自定义对话框上的视图未显示

  19. 19

    自定义对话框上的视图未显示

  20. 20

    自定义视图的适配器中的NullPointerException

  21. 21

    自定义适配器视图(带有图片)

  22. 22

    自定义列表适配器onClick方法返回空视图ID

  23. 23

    在自定义可扩展列表适配器中无法充实视图

  24. 24

    Android过滤器列表视图自定义适配器

  25. 25

    在自定义适配器列表视图中突出显示搜索到的文本

  26. 26

    使用外部XML文件进行自定义列表视图适配器?

  27. 27

    自定义适配器不会使列表视图中的行膨胀

  28. 28

    在自定义适配器的列表视图项中加载不同的图像

  29. 29

    我无法使用自定义适配器数据清除列表视图?

热门标签

归档