1

我試圖填補ListFragmentJSON內容,我與我的JSONParcer解析(擴展的AsyncTask)類。我還寫了CustomAdapter(擴展ArrayAdapter)由於具體的列表行佈局。所有的作品都很好,除了有沒有加載圈列表片段而它的加載(因爲它應該是默認情況下)。我怎樣才能找回來?沒有加載圈ListFragment

這裏是我的適配器代碼:

public class CustomAdapter extends ArrayAdapter<ListItem> 
{ 
    private final Activity context; 
    private final ListItem[] data; 

    public CustomAdapter(Activity context,ListItem[] itemz) 
    { 
    super(context, R.layout.list_item,itemz); 
    this.context = context; 
    this.data = itemz; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     LayoutInflater inflater = context.getLayoutInflater(); 
     View rowView = inflater.inflate(R.layout.list_item, null,true); 

     TextView txtTitle = (TextView) rowView.findViewById(R.id.title); 
     TextView txtBody = (TextView) rowView.findViewById(R.id.body); 
     ImageView imageView = (ImageView) rowView.findViewById(R.id.picture); 

     txtTitle.setText(data[position].getTitle()); 
     txtBody.setText(data[position].getBody()); 
     imageView.setImageBitmap(data[position].getPicture()); 

     return rowView; 
    } 
} 

回答

2

在您的通話ListFragmentsetListShown(false);隱藏ListView和顯示加載圖標。 當你想展示你的產品(它們加載後,處理,等等)電話:

if (isResumed()) 
    setListShown(true); 
else 
    setListShownNoAnimation(true); 
+0

加載後列表的內容仍然可見,即使有setListShown(false);在它之前 – user3090300

+0

@ user3090300 - 確保你調用setListAdapter(adapter);在你調用setListShown(false)之前; – dymmeh

0

您可以用的AsyncTask填補ListFragment,就像這樣:

private class fillFragmentList extends AsyncTask<Void, Void, Void> { 

    @Override 
    protected Void doInBackground(Void... arg0) { 
     // Heavy code 
     return null; 
    } 

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


    @Override 
    protected void onPostExecute(Void result) { 
     super.onPostExecute(result); 
     // Set the list adapter 
     setListAdapter(yourCustomAdapter); 
    } 
} 

這個類應該在擴展ListFragment的類。