2014-09-20 69 views
-3

我不能看到我的列表视图。我不知道问题在哪里。你能告诉我任何解决方案吗?我不能看到我的ListView

我的代码:

public class VerProyectos extends ActionBarActivity { 
private ListView listaProyectos; 

private ArrayList<datosProyectos> proyectos; 
private proyectosAdapter adaptador; 
private ProgressDialog pDialog; 

@SuppressLint("NewApi") @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_ver_proyectos); 
    ActionBar bar = getActionBar(); 
    bar.setTitle("Ver Proyectos"); 
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffa120"))); 

    proyectos=new ArrayList<datosProyectos>(); 
    listaProyectos = (ListView)findViewById(R.id.listaProyectos); 

    adaptador = new proyectosAdapter(VerProyectos.this); 
    //listaProyectos.setAdapter(adaptador); 

    listaProyectos.setOnScrollListener(new EndlessScrollListener()); 

} 


@SuppressLint("NewApi") @Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.ver_proyectos, menu);  
    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public void onBackPressed() { 
    Intent irAMenuInversor = new Intent(this, MenuInversor.class); 
    startActivity(irAMenuInversor); 
    finish(); 
} 

类TareaWSObtenerProyectos:

 class TareaWSObtenerProyectos extends AsyncTask<String,Integer,Boolean> { 

    private ArrayList<datosProyectos> proyectosAux; 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(VerProyectos.this); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(true); 
      pDialog.show();   
      pDialog.setContentView(R.layout.progress_dialog_personalizado);   
     } 

     protected Boolean doInBackground(String... params) { 

      boolean resul = true; 

      HttpClient httpClient = new DefaultHttpClient(); 

      HttpGet del = 
        new HttpGet("https://www.sociosinversores.es/service/proyectos?page="+params[0]); 

      del.setHeader("clave", "22c9b09e6b6667bc1da16f255488f8d0"); 


      try 
      {   
       HttpResponse resp = httpClient.execute(del); 
       String respStr = EntityUtils.toString(resp.getEntity()); 

       JSONObject respJSON = new JSONObject(respStr); 
       JSONArray proyectos = (JSONArray) respJSON.get("proyectos"); 
       //JSONArray jsonArray = new JSONArray(respJSON); 
       proyectosAux = new ArrayList<datosProyectos>(); 

       for(int i = 0; i < proyectos.length(); i++){      

         JSONObject json_data = proyectos.getJSONObject(i); 
         int idmensaje = json_data.getInt("ID"); 
         int inversion_minima = json_data.getInt("inversion_minima"); 
         int dinero_invertido = json_data.getInt("dinero_invertido"); 
         int dinero_proyecto = json_data.getInt("dinero_proyecto"); 
         String titulo = json_data.getString("post_title"); 
         String resumen = json_data.getString("post_excerpt"); 
         String url_imagen = json_data.getString("guid"); 
         int progreso=(int)(dinero_invertido*100)/dinero_proyecto; 
         /*Proyecto pro = new Proyecto(idmensaje,titulo,0, "", 
           resumen, inversion_minima,dinero_proyecto, 
           dinero_invertido,url_imagen,null);*/ 
         datosProyectos datos = new datosProyectos(dinero_proyecto, dinero_invertido, inversion_minima, 
           titulo, resumen, null, dinero_proyecto, progreso); 

         proyectosAux.add(datos); 

       } 


      } 
      catch(Exception ex) 
      { 
       Log.e("ServicioRest","Error!", ex); 
       resul = false; 
      } 

      return resul; 
     } 

     protected void onPostExecute(Boolean result) { 
      pDialog.dismiss(); 
      if (result) 
      { 
       if (adaptador.getCount()==0){ 
        listaProyectos.setAdapter(adaptador); 
       }else{ 
       //prog.hide(); 
       adaptador.setItemList(proyectosAux); 
       adaptador.notifyDataSetChanged(); 
       } 
      } 
     } 

    } 

类EndlessScrollListener:

public class EndlessScrollListener implements OnScrollListener { 

    private int visibleThreshold = 5; 
    private int currentPage = 0; 
    private int previousTotal = 0; 
    private boolean loading = false; 

    public EndlessScrollListener() { 
    } 
    public EndlessScrollListener(int visibleThreshold) { 
     this.visibleThreshold = visibleThreshold; 
    } 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, 
      int visibleItemCount, int totalItemCount) { 
     Log.d("Scroll","first: "+firstVisibleItem+"VisibleItem: "+visibleItemCount+"total_item : "+totalItemCount+"Load:"+loading+"previusTotal :"+previousTotal); 
     if (loading) { 

      if (totalItemCount > previousTotal) { 
       loading = false; 
       previousTotal = totalItemCount; 
       currentPage++; 
       Log.d("Scroll","Fin"); 
      } 
     } 
     if (!loading && (totalItemCount - firstVisibleItem) <= (visibleItemCount)) { 
      // I load the next page of gigs using a background task, 
      // but you can call any function here. 
      // new LoadGigsTask().execute(currentPage + 1); 
      //prog.show(); 
      (new TareaWSObtenerProyectos()).execute(String.valueOf(currentPage)); 
      loading = true; 
     } 
    } 

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

我的适配器:

public class proyectosAdapter extends ArrayAdapter<datosProyectos> { 
    private Context context; 
    private static ArrayList<datosProyectos> datos =new ArrayList<datosProyectos>(); 

    private ProgressBar bar; 
    private TextView titulo; 
    private TextView descripcion; 
    private TextView total; 
    private TextView invertido; 
    private TextView desde; 
    private ImageView imagen; 



    public proyectosAdapter(Context context, ArrayList<datosProyectos> proyectos) { 
     super(context, R.layout.cuadro_proyecto, datos); 
     this.context = context; 

    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     // En primer lugar "inflamos" una nueva vista, que será la que se 
     // mostrará en la celda del ListView. Para ello primero creamos el 
     // inflater, y después inflamos la vista. 
     LayoutInflater inflater = LayoutInflater.from(context); 
     View item = inflater.inflate(R.layout.cuadro_proyecto, null); 


     bar = (ProgressBar) item.findViewById(R.id.progressBar_proyecto); 
     titulo = (TextView) item.findViewById(R.id.textCategoria); 
     descripcion = (TextView) item.findViewById(R.id.textDescripcion); 
     total = (TextView) item.findViewById(R.id.textTotal); 
     invertido = (TextView) item.findViewById(R.id.textInvertido); 
     desde = (TextView) item.findViewById(R.id.textDesde);  
     imagen = (ImageView) item.findViewById(R.id.list_image_proyecto); 

     bar.setMax(datos.get(position).getBarTotal()); 
     bar.setProgress(datos.get(position).getBarProgreso()); 
     if (datos.get(position).getBarProgreso() >= datos.get(position).getBarTotal()){ 
      bar.getProgressDrawable().setColorFilter(Color.GREEN, Mode.SRC_IN); 
     } 

     titulo.setText(datos.get(position).getTitulo()); 
     descripcion.setText(datos.get(position).getDescripcion()); 
     total.setText(datos.get(position).getTotal()); 
     invertido.setText(datos.get(position).getInvertido()); 
     desde.setText(datos.get(position).getDesde()); 
     imagen.setImageBitmap(datos.get(position).getDibujo()); 

     return item; 
    } 

    public void setItemList(ArrayList<datosProyectos> a) { 
     // int num = datos.size(); 
     for(int i = 0; i < a.size(); i++){ 
      datos.add(a.get(i)); 
       /*if (num>0) 
       datos.get(num+i).loadImage(adaptador); 
       else 
       proyectos.get(i).loadImage(adaptador);*/ 
     } 


     } 
} 

回答

0

我看到的唯一的地方,你设置了AdapterListViewonPostExecute()

if (adaptador.getCount()==0){ 

但我没有看到你有这样的点之前设置在Adapter任何项目。只需设置您的Adapter,不管计数如何,然后按照onPostExecute()中的说明进行更新。

我还没有看到,你在呼唤你的AsyncTask但也许这是我的疏忽。