Android弹出窗口列表视图

时间:2013-08-25 00:00:26

标签: android facebook listview facebook-comments

我的项目中有一个弹出窗口。我在列表视图中收到了一组帖子。如果我点击列表视图中的帖子,将打开一个弹出窗口,其中包含帖子,帖子评论和喜欢;用户可以在该窗口中为该帖子添加评论和撰写评论。但我无法将我的评论数据绑定到弹出窗口的列表视图。下面是我的代码和logcat数据:

ListView lstcomment = (ListView)popup.getContentView().findViewById(R.id.lstcomments);
            CommentAdapter cmm = new CommentAdapter(this, commentarName, commentarPicture, commentarComment);
            System.out.println(cmm.getCount());
            if(cmm.getCount()>0)
            {
                lstcomment.setAdapter(cmm);
            }
            else
            {
                lstcomment.setVisibility(View.GONE);
                nocomment.setVisibility(View.VISIBLE);
            }

logcat的

08-25 02:54:27.680: E/AndroidRuntime(21581): FATAL EXCEPTION: main
08-25 02:54:27.680: E/AndroidRuntime(21581): java.lang.NullPointerException
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.CommentAdapter.getCount(CommentAdapter.java:39)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity.showFbPopup(MainActivity.java:1342)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity.access$9(MainActivity.java:1297)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.invemo.vodafonelivecoursetest.MainActivity$3.onItemClick(MainActivity.java:343)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AdapterView.performItemClick(AdapterView.java:315)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.widget.AbsListView$1.run(AbsListView.java:3168)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Handler.handleCallback(Handler.java:605)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.os.Looper.loop(Looper.java:137)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at android.app.ActivityThread.main(ActivityThread.java:4425)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at java.lang.reflect.Method.invokeNative(Native Method)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at java.lang.reflect.Method.invoke(Method.java:511)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
08-25 02:54:27.680: E/AndroidRuntime(21581):    at dalvik.system.NativeStart.main(Native Method)

如果我通过System.out.println将我的评论数据写入logcat,我可以获取数据,但我无法将它们写入listview。

我的适配器代码:

package com.invemo.vodafonelivecoursetest;


public class CommentAdapter extends BaseAdapter {

private Activity activity;
private String[]  profilePicture;
private String[] contentMessage;
private String[] sender;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public CommentAdapter(Activity a, String[] senders, String[] profilePictures, String[] announceContents) {
    activity = a;
    this.profilePicture=profilePictures;
    this.contentMessage=announceContents;
    this.sender=senders;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}



@Override
public int getCount() {
    return sender.length;
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}
public static class ViewHolder {
    public TextView textTitle;
    public ImageView image;
    public TextView contentArea;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.announce_item, null);
        holder = new ViewHolder();
        holder.textTitle = (TextView) vi.findViewById(R.id.textView1);
        holder.image = (ImageView) vi.findViewById(R.id.imageView1);
        holder.contentArea=(TextView)vi.findViewById(R.id.textView2);
        vi.setTag(holder);
    } else
        holder = (ViewHolder) vi.getTag();

    holder.textTitle.setText(sender[position]);
    holder.contentArea.setText(contentMessage[position]);
    holder.contentArea.setAutoLinkMask(Linkify.WEB_URLS);
    holder.image.setTag(profilePicture[position]);
    imageLoader.DisplayImage(profilePicture[position], activity, holder.image);
    return vi;
}

}

1 个答案:

答案 0 :(得分:0)

看起来commentarName必须为null。你确定在count方法调用.length之前给它赋值吗?