2011-08-31 110 views
0

我有一個列表視圖,並顯示帶有圖像數量的凸輪圖像。我的代碼如下Android:在列表視圖問題中設置圖像的可見性

  TextView imageCountview = (TextView) row.findViewById(R.id.TextViewImageCount); ; 
      //checking whether count is zero, if so hiding both image and count 
      if(ImageCount.equals("0")){ 
       imageCountview.setVisibility(8); 
       ImageView camimage = (ImageView) row.findViewById(R.id.imageViewlistcam); 
       camimage.setVisibility(8); 
      } 
      else{ 
       imageCountview.setText(ImageCount); 
      } 

現在我的問題是,當列表加載時,everyhing很好,當count大於零時顯示圖像。現在我一直在向列表視圖添加更多元素,直到它使滾動條。問題現在開始

當我向上滾動時,部分列表元素會進入預期行爲的屏幕後面。當我向下滾動時,即使之前顯示,圖像也會消失。它在列表中非常不尋常的行爲。我在這裏錯過了什麼?有人可以幫我嗎。

感謝您的時間提前。

我的適配器

class MyIncidentAdapter extends ArrayAdapter{ 

     public MyIncidentAdapter(Context context, int textViewResourceId, 
       ArrayList<String> dbResults) { 
      super(context, textViewResourceId, dbResults); 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      View row = convertView; 
      if (row == null) { 
       LayoutInflater inflater = getLayoutInflater(); 
       row = inflater.inflate(R.layout.row_incident, parent, false); 
      } 

      TextView incidentID = (TextView) row.findViewById(R.id.label_incident); 
      incidentID.setText((db_results.get(position)).toString()); 

      String Final = null; 
      String ImageCount = "0"; 
      String VideoCount = "0"; 
      String RecordingCount="0"; 
      //getting image count 
      SQLiteDatabase db10; 
      db10 = openOrCreateDatabase("filestore", MODE_PRIVATE, null); 
      Cursor cursor = db10.rawQuery(
        "SELECT count(urls) as numbers FROM files where incident_id='"+((db_results.get(position)).toString())+"'", null); 
      while (cursor.moveToNext()) { 
       ImageCount = String.valueOf(cursor.getString(cursor 
         .getColumnIndex("numbers"))); 
      } 
      cursor.close(); 

      //getting video 
      Cursor cursor1 = db10.rawQuery(
        "SELECT count(urls) as numbers FROM videos where incident_id='"+((db_results.get(position)).toString())+"'", null); 
      while (cursor1.moveToNext()) { 
       VideoCount = String.valueOf(cursor1.getString(cursor1 
         .getColumnIndex("numbers"))); 
      } 
      cursor1.close(); 

      //getting audio count 
      Cursor cursor11 = db10.rawQuery(
        "SELECT count(urls) as numbers FROM audios where incident_id='"+((db_results.get(position)).toString())+"'", null); 
      while (cursor11.moveToNext()) { 
       RecordingCount = String.valueOf(cursor11.getString(cursor11 
         .getColumnIndex("numbers"))); 
      } 
      cursor11.close(); 



      //Final = "Image:"+ImageCount+ "  Video:"+VideoCount+ "  Audio:"+RecordingCount; 
      //TextView countinfo = (TextView) row.findViewById(R.id.textViewCount); 
      //countinfo.setText(Final); 

      TextView imageCountview = (TextView) row.findViewById(R.id.TextViewImageCount); ; 
      //checking whether count is zero, if so hiding both image and count 
      if(ImageCount.equals("0")){ 
       imageCountview.setVisibility(8); 
       ImageView camimage = (ImageView) row.findViewById(R.id.imageViewlistcam); 
       camimage.setVisibility(8); 
      } 
      else{ 
       imageCountview.setText(ImageCount); 
      } 


      TextView videoCountview = (TextView) row.findViewById(R.id.textViewVideoCount); 
      if(VideoCount.equals("0")){ 
       videoCountview.setVisibility(8); 
       ImageView imgvid = (ImageView)row.findViewById(R.id.imageViewlistvid); 
       imgvid.setVisibility(8); 
      } 
      else{ 
       videoCountview.setText(VideoCount); 
      } 


      TextView audioCountview = (TextView) row.findViewById(R.id.textViewAudioCount); 
      if(RecordingCount.equals("0")){ 
       audioCountview.setVisibility(8); 
       ImageView audioimg = (ImageView)row.findViewById(R.id.imageViewlistaud); 
       audioimg.setVisibility(8); 
      } 
      else{ 
       audioCountview.setText(RecordingCount); 
      } 

      String InsDate=null; 
      Cursor cursor111 = db10.rawQuery(
        "SELECT incident_date FROM incident where incident_id='"+((db_results.get(position)).toString())+"'", null); 
      while (cursor111.moveToNext()) { 
       InsDate = String.valueOf(cursor111.getString(cursor111 
         .getColumnIndex("incident_date"))); 
      } 
      cursor111.close(); 

      TextView incidentDate = (TextView) row.findViewById(R.id.label_date); 
      incidentDate.setText(InsDate); 

      Cursor cursor1111 = db10.rawQuery(
        "SELECT description FROM incident where incident_id='"+((db_results.get(position)).toString())+"'", null); 
      while (cursor1111.moveToNext()) { 
       description = String.valueOf(cursor1111.getString(cursor1111 
         .getColumnIndex("description"))); 
      } 
      cursor1111.close(); 
      db10.close(); 
      TextView incidentDesc = (TextView) row.findViewById(R.id.label_des); 


      if(description.equals(" ")){ 
       incidentDesc.setVisibility(8); 
      } 
      else{ 
       incidentDesc.setText(description.trim()); 
      } 



      return row; 
     } 
+0

需要查看您的getView適配器。 – Ronnie

+0

我已經更新了我的適配器,現在請您檢查一下。 –

回答

0

找到的答案是quesiton。簡單我必須再次顯示我曾經隱藏使用setvisibility方法。

1

null父參數設置爲膨脹的API。

row = inflater.inflate(R.layout.row_incident, null, false); 
+0

我禁用了scrollview緩存,它工作:) –

+0

這是否有幫助?..你是怎麼做到的? – Ronnie

+0

ohh對不起,它工作了一段時間,並沒有工作。我以前設置了listview的android:scrollingCache =「false」,它工作了一段時間,不再工作。你的方法也沒有幫助:(好難過 –

相關問題