2016-02-05 60 views
0

我知道,這是一個非常常見的話題。 我正在關注有關此行爲的所有主題和文檔,但任何解決方案都適用於我。從BaseAdapter擴展的GetView沒有運行Runnable任務

我有我的適配器: ListAdapter

public class ListAdapterForFragment extends BaseAdapter { 

    NewsFragment main; 

    public ListAdapterForFragment(NewsFragment main){ 
     this.main = main; 
    } 

    @Override 
    public int getCount() { 
     return main.countries.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     return 0; 
    } 

    static class ViewHolderItem { 
     TextView name; 
     TextView code; 
     ImageView imageView2; 
     TextView id; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
     ViewHolderItem holder = new ViewHolderItem(); 
     if (convertView == null) { 
      LayoutInflater inflater = (LayoutInflater) main.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = inflater.inflate(R.layout.cell, null); 

      //asigning all the holders and values 
     } 
     else 
     { 
      holder = (ViewHolderItem) convertView.getTag(); 
     } 

     //More code 

     return convertView; 
    } 

} 

MyFragment

public void onViewCreated(View v, Bundle savedInstanceState) { 
    super.onViewCreated(v, savedInstanceState); 
    //super.onPostExecute(result); 
    text.setText("hola mundo"); 

    adapter = new ListAdapterForFragment(this); 
    list.setAdapter(adapter); 

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
     } 
    }); 

    Download_data download_data = new Download_data((Download_data.download_complete) this); 
    download_data.download_data_from_link("http://cloud.anda.gob.sv/sm/Home/ObtenerDenunciasNoResueltas"); 
} 

@Override 
public void get_data(String data) { 
    try { 
     JSONArray data_array = new JSONArray(data); 

     for (int i = 0; i < data_array.length(); i++) { 
      JSONObject obj = new JSONObject(data_array.get(i).toString()); 

      Den add = new Den(); 
      add.type = obj.getString("type"); 
      add.desc = obj.getString("desc"); 
      add.PhotoURL = obj.getString("URL"); 
      add.Id = Integer.parseInt(obj.getString("Id")); 
      add.Latitud = Double.parseDouble(obj.getString("Latitud")); 
      add.Longitud = Double.parseDouble(obj.getString("Longitud")); 
      countries.add(add); 
     } 

     adapter.notifyDataSetChanged(); 

    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
} 

適配器正在執行adapter.notifyDataSetChanged();並在第一時間,main.countries.size();返回0,但返回6後 但是,方法GetView()未執行。 我該如何解決它?

回答

1

如果您在構建國家/地區列表後調用setAdapter,它會起作用嗎?

你包含的代碼不是很清楚。有沒有AsyncTask的地方?