1

수집 할 수있는 것부터 ListView가 표시되지 않아서 getCount가 0이 아닌 값을 반환한다는 것을 확인했습니다. 내가 뭘 잘못하고 있는지 보지마.ListFragment 렌더링되지 않고 어댑터의 getView() 호출되지 않음

모든 것이로드되고 작동하지만 ListView가 나타나지 않습니다. mixed.xml의 조각 참조에 배경색을 지정하고 거기에 전체 화면을 차지하고 있지만 배경색을 설정할 때 ListView는 나타나지 않습니다. 렌더링되지 않은 것 같습니다.

내 어댑터에서 getView가 호출되지 않는 경우가 많습니다. 이것은 파편에 이식 한 일반적인 작업의 모든 작동 코드입니다.

내가 디버깅 어댑터가 데이터로 채워지고 getCount는 참으로 정확하게 계산에게 어떤 도움이 0보다 큰

감사를 반환 보여주고, 아무것도 변경되지 않았다 notifyDataSetChanged를 호출 시도했습니다, 나는 붙어 .

프로젝트가 열려 있고 여기서 볼 수 있습니다 http://code.google.com/p/shack-droid/source/browse/#svn%2FTrunk하지만 여기에 관련 코드도 포함되어 있습니다. 여기

public class FragmentTopicView extends ListFragment implements ShackGestureEvent { 

     private ArrayList<ShackPost> posts; 
     private String storyID = null; 

     private String errorText = ""; 
     private Integer currentPage = 1; 
     private Integer storyPages = 1; 
     private String loadStoryID = null; 
     private Boolean threadLoaded = true; 
     private Hashtable<String, String> postCounts = null; 
     private AdapterLimerifficTopic tva; 

     public FragmentTopicView() { 

     } 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
       // TODO Auto-generated method stub 
       super.onCreate(savedInstanceState); 

       this.setRetainInstance(true); 
     } 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

       return inflater.inflate(R.layout.topics, null); 
     } 

     @Override 
     public void onActivityCreated(Bundle savedInstanceState) { 
       super.onActivityCreated(savedInstanceState); 

       final ShackGestureListener listener = Helper.setGestureEnabledContentView(R.layout.topics, getActivity()); 
       if (listener != null) { 
         listener.addListener(this); 
       } 

       if (savedInstanceState == null) { 
         // get the list of topics 
         GetChattyAsyncTask chatty = new GetChattyAsyncTask(getActivity()); 
         chatty.execute(); 
       } 

       ListView lv = getListView(); 
       lv.setOnScrollListener(new OnScrollListener() { 

         @Override 
         public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 

           // start loading the next page 
           if (threadLoaded && firstVisibleItem + visibleItemCount >= totalItemCount && currentPage + 1 <= storyPages) { 

             // get the list of topics 
             currentPage++; 
             GetChattyAsyncTask chatty = new GetChattyAsyncTask(getActivity()); 
             chatty.execute(); 

           } 
         } 

         @Override 
         public void onScrollStateChanged(AbsListView view, int scrollState) { 

         } 

       }); 



     } 



    class GetChattyAsyncTask extends AsyncTask<String, Void, Void> { 
       protected ProgressDialog dialog; 
       protected Context c; 

       public GetChattyAsyncTask(Context context) { 
         this.c = context; 
       } 

       @Override 
       protected Void doInBackground(String... params) { 

         threadLoaded = false; 

         try { 
           final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); 
           final String feedURL = prefs.getString("shackFeedURL", getString(R.string.default_api)); 
           final URL url; 

           if (loadStoryID != null) { 
             if (currentPage > 1) 
               url = new URL(feedURL + "/" + loadStoryID + "." + currentPage.toString() + ".xml"); 
             else 
               url = new URL(feedURL + "/" + loadStoryID + ".xml"); 
           } 
           else { 
             if (currentPage > 1) 
               url = new URL(feedURL + "/" + storyID + "." + currentPage.toString() + ".xml"); 
             else 
               url = new URL(feedURL + "/index.xml"); 
           } 

           // Get a SAXParser from the SAXPArserFactory. 
           final SAXParserFactory spf = SAXParserFactory.newInstance(); 
           final SAXParser sp = spf.newSAXParser(); 

           // Get the XMLReader of the SAXParser we created. 
           final XMLReader xr = sp.getXMLReader(); 
           // Create a new ContentHandler and apply it to the XML-Reader 
           SaxHandlerTopicView saxHandler = new SaxHandlerTopicView(c, "topic"); 

           xr.setContentHandler(saxHandler); 

           // Parse the xml-data from our URL. 
           xr.parse(new InputSource(HttpHelper.HttpRequestWithGzip(url.toString(), c))); 

           // Our ExampleHandler now provides the parsed data to us. 
           if (posts == null) { 
             posts = saxHandler.GetParsedPosts(); 
           } 
           else { 
             ArrayList<ShackPost> newPosts = saxHandler.GetParsedPosts(); 
             newPosts.removeAll(posts); 
             posts.addAll(posts.size(), newPosts); 

           } 

           storyID = saxHandler.getStoryID(); 

           storyPages = saxHandler.getStoryPageCount(); 

           if (storyPages == 0) // XML returns a 0 for stories with only 
                       // one page 
             storyPages = 1; 

         } 
         catch (Exception ex) { 
           // TODO: implement error handling 

         } 

         return null; 
       } 

       @Override 
       protected void onPreExecute() { 
         super.onPreExecute(); 

         if (currentPage == 1) 
           dialog = ProgressDialog.show(getActivity(), null, "Loading Chatty", true, true); 
         else 
           SetLoaderVisibility(View.VISIBLE); 
       } 

       @Override 
       protected void onPostExecute(Void result) { 
         super.onPostExecute(result); 

         ShowData(); 

         SetLoaderVisibility(View.GONE); 

         try { 
           dialog.dismiss(); 
         } 
         catch (Exception e) { 
         } 

       } 

     } 



    private void ShowData() { 

       if (posts != null) { 
         Hashtable<String, String> tempHash = null; 

         final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); 
         final String login = prefs.getString("shackLogin", ""); 
         final int fontSize = Integer.parseInt(prefs.getString("fontSize", "12")); 

         try { 
           postCounts = GetPostCache(); 
         } 
         catch (Exception ex) { 

         } 
         if (postCounts != null) 
           tempHash = new Hashtable<String, String>(postCounts); 

         if (tva == null) { 
           tva = new AdapterLimerifficTopic(getActivity(), R.layout.lime_topic_row, posts, login, fontSize, tempHash); 
           setListAdapter(tva); 
         } 
         else { 
           tva.SetPosts(posts); 
           tva.notifyDataSetChanged(); 
         } 

         final ListView lv = getListView(); 
         lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { 
           @Override 
           public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { 
             menu.setHeaderTitle("Options"); 
             menu.add(0, 1, 0, "Copy Post Url to Clipboard"); 
             menu.add(0, 2, 0, "Watch Thread"); 
             menu.add(0, 3, 0, "Thread Expires In?"); 
             menu.add(0, 4, 0, "Shacker's Chatty Profile"); 
           } 
         }); 

         // update the reply counts for the listing of topics 
         try { 
           UpdatePostCache(); 

         } 
         catch (Exception e) { 

         } 

       } 
       else { 
         if (errorText.length() > 0) { 

           try { 
             new AlertDialog.Builder(getActivity()).setTitle("Error").setPositiveButton("OK", null).setMessage(errorText).show(); 
           } 
           catch (Exception ex) { 
             // could not create a alert for the error for one reason 
             // or another 
             Log.e("ShackDroid", "Unable to create error alert ActivityTopicView:468"); 
           } 
         } 
       } 
       threadLoaded = true; 
     } 

} 

내 FragmentActivity입니다 :

public class FragmentActivityTopic extends FragmentActivity { 
     @Override 
     protected void onCreate(Bundle arg) { 
       // TODO Auto-generated method stub 
       super.onCreate(arg); 

       setContentView(R.layout.mixed); 
     } 
} 

이것은 내가 사용 어댑터이며,의 getView 위에서 언급 한 바와 같이 호출되는되지 않습니다

public class AdapterLimerifficTopic extends BaseAdapter { 

     // private Context context; 
     private List<ShackPost> topicList; 
     private final int rowResouceID; 
     private final String shackLogin; 
     private final Typeface face; 
     private final int fontSize; 
     private final Hashtable<String, String> postCache; 
     private final String showAuthor; 
     private final Resources r; 
     private int totalNewPosts = 0; 

     LayoutInflater inflate;// = LayoutInflater.from(context); 

     public AdapterLimerifficTopic(Context context, int rowResouceID, List<ShackPost> topicList, String shackLogin, int fontSize, Hashtable<String, String> postCache) { 
       this.topicList = topicList; 
       this.rowResouceID = rowResouceID; 
       this.shackLogin = shackLogin; 
       this.fontSize = fontSize; 
       this.postCache = postCache; 
       this.r = context.getResources(); 

       face = Typeface.createFromAsset(context.getAssets(), "fonts/arial.ttf"); 

       final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 
       showAuthor = prefs.getString("showAuthor", "count"); 

       inflate = LayoutInflater.from(context); 
     } 
     public void SetPosts(List<ShackPost> posts) 
     { 
       topicList = posts; 
     } 
     @Override 
     public int getCount() { 
       return topicList.size(); 
     } 

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

     @Override 
     public long getItemId(int position) { 
       // return position; 
       final ShackPost post = topicList.get(position); 
       return Long.parseLong(post.getPostID()); 
     } 

     static class ViewHolder { 
       TextView posterName; 
       TextView datePosted; 
       TextView replyCount; 
       TextView newPosts; 
       TextView postText; 
       TextView viewCat; 
       RelativeLayout topicRow; 
       ImageView postTimer; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 

       // TextView tmp; 
       // final View v; 
       ViewHolder holder; 
       final ShackPost post = topicList.get(position); 

       if (convertView == null) { 
         convertView = inflate.inflate(rowResouceID, parent, false); 
         holder = new ViewHolder(); 
         holder.posterName = (TextView) convertView.findViewById(R.id.TextViewLimeAuthor); 
         holder.datePosted = (TextView) convertView.findViewById(R.id.TextViewLimePostDate); 
         holder.replyCount = (TextView) convertView.findViewById(R.id.TextViewLimePosts); 
         holder.newPosts = (TextView) convertView.findViewById(R.id.TextViewLimeNewPosts); 
         holder.postText = (TextView) convertView.findViewById(R.id.TextViewLimePostText); 
         holder.viewCat = (TextView) convertView.findViewById(R.id.TextViewLimeModTag); 
//      holder.topicRow = (RelativeLayout) convertView.findViewById(R.id.TopicRow); 
//      holder.postTimer = (ImageView) convertView.findViewById(R.id.ImageViewTopicTimer); 

//      holder.posterName.setTypeface(face); 
//      holder.datePosted.setTypeface(face); 
//      holder.replyCount.setTypeface(face); 
//      holder.newPosts.setTypeface(face); 
         holder.postText.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize); 
//      holder.postText.setTypeface(face); 

         convertView.setTag(holder); 
       } 
       else { 
         holder = (ViewHolder) convertView.getTag(); 
       } 

//    holder.postTimer.setImageResource(Helper.GetTimeLeftDrawable(post.getPostDate())); 
// 
       holder.posterName.setText(post.getPosterName()); 
// 
//    if (shackLogin.equalsIgnoreCase(post.getPosterName())) 
//      holder.posterName.setTextColor(Color.parseColor("#00BFF3")); 
//    else 
//      holder.posterName.setTextColor(Color.parseColor("#ffba00")); 
// 
       holder.datePosted.setText(Helper.FormatShackDateToTimePassed(post.getPostDate())); 

       holder.replyCount.setText(post.getReplyCount()); 
// 
//    if (showAuthor.equalsIgnoreCase("count") && post.getIsAuthorInThread()) 
//      holder.replyCount.setTextColor(Color.parseColor("#0099CC")); 
//    else 
//      holder.replyCount.setTextColor(Color.parseColor("#FFFFFF")); 
// clipped code 
       holder.postText.setText(preview); 


//    if (showAuthor.equalsIgnoreCase("topic") && post.getIsAuthorInThread()) { 
//      final Drawable d = r.getDrawable(R.drawable.background_gradient_blue); 
//      holder.topicRow.setBackgroundDrawable(d); 
//    } 
//    else 
//      holder.topicRow.setBackgroundDrawable(null); 


       // TODO: clean this up a little/also replicated in ShackDroidThread ick 
       final String postCat = post.getPostCategory(); 
       holder.viewCat.setVisibility(View.VISIBLE); 

       if (postCat.equals("offtopic")) { 
         holder.viewCat.setText("offtopic"); 
         holder.viewCat.setBackgroundColor(Color.parseColor("#444444")); 
       } 
       else if (postCat.equals("nws")) { 
         holder.viewCat.setText("nws"); 
         holder.viewCat.setBackgroundColor(Color.parseColor("#CC0000")); 
       } 
       else if (postCat.equals("political")) { 
         holder.viewCat.setText("political"); 
         holder.viewCat.setBackgroundColor(Color.parseColor("#FF8800")); 
       } 
       else if (postCat.equals("stupid")) { 
         holder.viewCat.setText("stupid"); 
         holder.viewCat.setBackgroundColor(Color.parseColor("#669900")); 
       } 
       else if (postCat.equals("informative")) { 
         holder.viewCat.setText("interesting"); 
         holder.viewCat.setBackgroundColor(Color.parseColor("#0099CC")); 
       } 
       else 
         holder.viewCat.setVisibility(View.GONE);     


       return convertView; 
     } 

     public int getTotalNewPosts() { 
       return totalNewPosts; 
     } 

} 

는 ListFragment입니다

관련 XML :

,515,

mixed.xml (이 지금 단편의 레이아웃 만이다)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:id="@+id/LinearLayoutMixed"> 

    <fragment 
     android:id="@+id/MixedThreads" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     class="com.stonedonkey.shackdroid.FragmentTopicView" 
     > 
    </fragment> 

</LinearLayout> 

Topics.xml (이리스트 뷰뿐만 아니라 슬라이딩 트레이와 다른 재료를 포함한다.

<?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 

      <ListView 
       android:id="@android:id/list" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_above="@+id/TopicLoader" 
       android:divider="#333333" 
       android:dividerHeight="1dip" 
       android:textColor="#FFFFFF" 

       /> 

      <RelativeLayout 
       android:id="@+id/TopicLoader" 
       android:layout_width="fill_parent" 
       android:layout_height="35dip" 
       android:layout_alignParentBottom="true" 
       android:gravity="center_horizontal" 
       android:visibility="gone" 
       android:layout_marginTop="5dip" > 

       <TextView 
        android:id="@+id/TextViewTopicLoaderText" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:focusable="false" 
        android:focusableInTouchMode="false" 
        android:text="Loading" 

        > 
       </TextView> 

       <ImageView 
        android:id="@+id/ImageViewTopicLoader" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/TextViewTopicLoaderText" 
        android:src="@drawable/ic_action_refresh" 
        android:layout_alignBottom="@+id/TextViewTopicLoaderText" 
        /> 
      </RelativeLayout> 

      <SlidingDrawer 
       android:id="@+id/SlidingDrawer01" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_below="@+id/TopicLoader" 
       android:animateOnClick="true" 
       android:content="@+id/bookMarkParent" 
       android:handle="@+id/TextViewTrayHandle" 
       android:orientation="vertical" 
       android:paddingTop="200dip" 
       android:visibility="gone" > 

       <TextView 
        android:id="@+id/TextViewTrayHandle" 
        android:layout_width="fill_parent" 
        android:layout_height="35dip" 
        android:background="@drawable/darkgrey_gradient" 
        android:focusable="false" 
        android:focusableInTouchMode="false" 
        android:gravity="center_vertical" > 
       </TextView> 

       <RelativeLayout 
        android:id="@id/bookMarkParent" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" > 

        <ListView 
         android:id="@+id/ListViewWatchedThreads" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:divider="#333333" 
         android:dividerHeight="1dip" 
         android:textColor="#FFFFFF" > 
        </ListView> 
       </RelativeLayout> 
      </SlidingDrawer> 

     </RelativeLayout> 

그리고 마지막으로는 lime_topic_row 위의 레이아웃 ListView에 대한 내 사용자 지정 행 레이아웃이다 :

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#FF0000" > 

     <TextView 
      android:id="@+id/TextViewLimeModTag" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#FF0000" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="10dip" 
      android:textColor="#000000" 
      android:padding="2dip" 
      android:textSize="10dip" 
      />  
     <TextView 
      android:id="@+id/TextViewLimePostText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:minHeight="20dip" 
      android:padding="10dip" 
      android:layout_below="@+id/TextViewLimeModTag" 
      android:textColor="#FFFFFF" /> 

     <TextView 
      android:id="@+id/TextViewLimeAuthor" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/TextViewLimePostText" 
      android:paddingBottom="10dip" 
      android:paddingLeft="10dip" 
      android:textColor="#0099CC" /> 

     <TextView 
      android:id="@+id/TextViewPosted" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/TextViewLimePostText" 
      android:layout_toRightOf="@+id/TextViewLimeAuthor" 
      android:paddingBottom="10dip" 
      android:text=" posted " /> 

     <TextView 
      android:id="@+id/TextViewLimePostDate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/TextViewLimePostText" 
      android:layout_toRightOf="@+id/TextViewPosted" 
      android:paddingBottom="10dip" 
      android:paddingRight="10dip" 
      android:textColor="#FF8800" /> 



     <TextView 
      android:id="@+id/TextViewLimePosts" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/TextViewLimePostDate" 
      android:layout_marginRight="3dip" 
      android:layout_below="@+id/TextViewLimePostText" 
      android:layout_marginBottom="15dip" 
      android:layout_toLeftOf="@+id/TextViewLimeNewPosts" 
      android:background="#BBBBBB" 
      android:padding="3dip" 
      android:minWidth="25dip" 
      android:gravity="center" 
      android:textColor="#000000" /> 

     <TextView 
      android:id="@+id/TextViewLimeNewPosts" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/TextViewLimePostDate" 
      android:layout_below="@+id/TextViewLimePostText" 
      android:layout_marginBottom="15dip" 
      android:layout_marginRight="10dip" 
      android:background="#669900" 
      android:padding="3dip" 
      android:minWidth="25dip" 
      android:gravity="center" 
      android:layout_alignParentRight="true" 
      android:textColor="#000000" /> 

    </RelativeLayout> 
+0

어디에서 어댑터를 listview로 설정 했습니까? –

+0

완료 후 AsyncTask에서 호출되는 ShowData() 메서드의 ListFragment에 설정됩니다. – stonedonkey

+0

프로젝트의 파일이있는 아카이브를 어디에 둘 수 있습니까? 코드를 살펴보고 싶지만 작업하지 않거나 전복이 있으며 저장소에서 파일별로 파일을 복사하고 싶지 않습니다. – Luksprog

답변

1

내가 문제를 발견 한 것 같아요. 사용자가 환경 설정에서 또는 안드로이드 버전의 경우 제스처를 사용할 경우 확인 setGestureEnabledContentView() 방법에서

final ShackGestureListener listener = Helper.setGestureEnabledContentView(R.layout.topics, getActivity()); 
if (listener != null) { 
    listener.addListener(this); 
} 

참조하려면 다음 문제는 당신이 (가) FragmentTopicView에서 onActivityCreated 방법의 시작에 설치가 ShackGestureListener이 나타납니다 어느 쪽이든 true 또는 falseFragmentActivityTopic에 대한 콘텐츠 뷰를 다시 (FragmentTopicView의 레이아웃으로)으로 설정했습니다. 콘텐츠 뷰를 다시 설정하면 불행히도 ListView에 문제가없는 데이터 (ListView)가있는 현재 레이아웃을 처리 할 수 ​​있습니다.데이터를 가져 오기 위해 AsyncTasks을 실행하면 getListView에 올바른 ListView이 반환됩니다. getListViewonCreateView 메서드에서 설정 한 이전의 올바른 ListView에 대한 참조를 보유하기 때문에 데이터는 올바르게 설정되지만, 당신이이 ListView을 커버하기 때문에 setGestureEnabledContentView에서 아무것도 볼 수 없습니다.

이 동작은 HelperHelperAPI4 클래스의 활동에 대한 콘텐츠보기를 설정하는 줄을 간단하게 주석 처리 (또는 제거)하면 쉽게 볼 수 있습니다. ListView이 적용되는 다른 방법은 예를 들어 ListView (tva)의 어댑터를 getListView을 사용하고 getActivity().findViewById(android.R.id.list)을 사용하여 설정하는 것입니다 (메뉴 항목 중 하나를 선택할 때이 작업을 수행 했으므로 언제 제어 할 수 있습니까? 나는 확실히 당신이 무슨 일을하는지 이해하지 않는 한 해결책으로 추천 모르는

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    Intent intent; 
    switch (item.getItemId()) 
    { 
    case R.id.topic_menu_newpost: // Launch post form 
//this doesn't work as the getListView will return a reference to the old ListView 
ListView lv = getListView(); 
lv.setAdapter(tva); 
// this will work as you get a reference to the new ListView on top 
ListView lv = (ListView) getActivity().findViewById(android.R.id.list); 
lv.setAdapter(tva); 

하지만 나는 그것이의 콘텐츠보기를 설정해야합니다 의심 : 나는) 어댑터를 교체 다시 활동을해야합니다.