2016-12-28 45 views
1

我有一個代碼,至極裝載的消息列表:刷新後爲什麼列表視圖線是白色的?

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 代碼,其中i加載消息:

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

這裏的代碼,在這裏我選擇「更新行「:

@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); 
} 

如何解決這個白色的行?

我在Android上削減了一些代碼,但是您可以在github找到完整的代碼。 這是我的第一個項目,它寫的不是最佳.. 如果你知道如何寫這段代碼更明智:請告訴我。

編輯:佈局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" 
/> 
+1

「rsse_lement」的帖子佈局。 –

回答

1

你必須設置你的行文本視圖,黑色的文本顏色,這個問題將是修復,下面的代碼將幫助您:

android:textColor="@color/black" 
1

你可以試試這個

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

您的列表視圖中的每個單元