奇怪的ListView分隔行为

时间:2015-12-26 05:48:19

标签: android listview android-listview

我在使用ListView分隔符时遇到了一些问题。

如您所见,在第一张图片(Image 1)中,分隔符比第二张(Image2)中的“更厚”或“更暗”。

只要ListView所在的片段被提交(通过替换),就会发生Image 1。

然后,当我点击某个项目,然后按后退按钮(从后台弹出交易)时,分隔符就像第二张图片中一样。

有一点需要注意的是,如果我点击第一张图片中的分割器较暗的项目,选择的颜色为黄色,而如果我点击第二张图片,则选择为蓝色。 / p>

当我第一次创建de app时,它总是像第二张图片一样,这就是我想要它的方式。

我在网上找不到任何东西......为什么会这样? 也许是与适配器有关?提前谢谢。

的ListView:

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/activity_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/notification_list"
    />

用于设置ListView所在的片段的方法:

 private void changeToFragment(Fragment fragment, boolean addToBackStack) {
    mDrawerLayout.closeDrawer(Gravity.START);
    FragmentManager fragmentManager = getSupportFragmentManager();
    android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentManager.popBackStack();
    if (menuIsOpened)
        fragmentTransaction.setCustomAnimations( R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out);
    fragmentTransaction.replace(R.id.frame_container, fragment);
    if (addToBackStack)
        fragmentTransaction.addToBackStack("menuOptionSelected");
    fragmentTransaction.commit();

}

启用此方法:

changeToFragment (new NotificationsFragment(), false);

通知片段:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.activity_notifications, container, false);

    // The ListView that will display the norifications
    final ListView notificationList = (ListView)         rootView.findViewById(R.id.notification_list);

    // We create and fill the adapter with the notifications and set it to the ListView
    notifications = NotificationBuilder.getNotifications();
    listAdapter = new NotificationAdapter(getActivity(), R.layout.notification_layout, notifications);
    notificationList.setAdapter(listAdapter);

     ...some code...

    return rootView;
}

适配器getView方法:

    public View getView(int position, View convertView, ViewGroup viewGroup) {
        EduCloudNotification notification = notifications.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.notification_layout, null);
        }
        TextView title = (TextView) convertView.findViewById(R.id.notification_title);
        title.setText(notification.getTitle());

        TextView description = (TextView) convertView.findViewById(R.id.notification_description);
        description.setText(notification.getDescription());

        ImageView icon = (ImageView) convertView.findViewById(R.id.notification_icon);
        icon.setImageResource(notification.getIconId());

    return convertView;
}

0 个答案:

没有答案