Why list view lines are white after refresh?

119 views Asked by At

I have a code, wich load a list of news:

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view=inflater.inflate(R.layout.fragment_main, container, false);
    final RssLoader loader=new RssLoader(getContext(),getActivity());
    loader.loadFeeds();
    ListView listView= (ListView) view.findViewById(R.id.listViewNews);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) 
          {
            RssItem item=loader.getRssItems().get(i);
            if(item==null)
                return;
            startActivity(launchBrowser);
        }
    });

Here the list view after first download Code, where i load news:

   public void loadFeeds() {
    String[] urlArr = {"http://www.news.ru/export/news.xml"};
 new RssReader(_context)
            .showDialog(false)
            .urls(urlArr)
            .parse(new OnRssLoadListener() {
                @Override
                public void onSuccess(List<RssItem> rssItems) {

                    ArrayList<String> titles=new ArrayList<>();
                    if(rssItems.size()!=0)
                    {
                        titles.clear();
                    }

                    Toast.makeText(_context, rssItems.get(0).getTitle(), 
                    for (RssItem item:rssItems
                            ) {
                        RssItems.add(item);
                        titles.add(item.getTitle()+"\n"+item.getPubDate());
                    }

                    ArrayAdapter<String> adapter=new ArrayAdapter<String>(_context,R.layout.rsse_lement,titles);
                    //ArrayAdapter<String> adapter=new ArrayAdapter<String>(_context,R.layout.support_simple_spinner_dropdown_item,titles);
                    ListView listNewNews= (ListView) _activity.findViewById(R.id.listViewNews);

                    SharedData.adapter=adapter;//here i try to fiz bug..
                    listNewNews.setAdapter(SharedData.adapter);
                    }
                }

                @Override
                public void onFailure(String message) {
                }
            });
}

White rows after update

Here the code, where i select "Update rows":

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();       
    if (id == R.id.action_settings) {
        if(SharedData.adapter!=null)
        {
            SharedData.adapter.clear();
        }
        final RssLoader loader=new RssLoader(getApplicationContext(),this);
        loader.loadFeeds();
        ListView listView= (ListView) findViewById(R.id.listViewNews);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(loader.getRssItems().isEmpty())
                {
                    return;
                }

                RssItem item=loader.getRssItems().get(i);
                if(item==null)
                    return;
                //start new activity with text of news
                Intent launchBrowser = new Intent(getApplicationContext(), PageActivity.class);               
                startActivity(launchBrowser);
            }
        });         
        return true;
    }
    return super.onOptionsItemSelected(item);
}

How to fix this white rows?

I cut some code on Android, but you can find a full code at github. It is my first project and it writes not optimal.. If you know how to write this code more wisely: please tell me.

EDIT: layout rss_element:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvRssElement"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:maxLines="5"
android:maxLength="120"
android:ellipsize="end"
/>
2

There are 2 answers

0
Anjali On

You have to set text color of your row text view to black and this issue will be fix, below code will help you:

android:textColor="@color/black"
0
Apoorv Mehrotra On

you can try this

subscribebtn.setBackgroundResource(Color.WHITE);
 subscribebtn.setTextColor(Color.BLACK);

for each cell of your list view