2014-04-18 47 views
2

我在我的xml中創建了一個表來顯示一些信息。但是文本並沒有加載到表格中。我知道文本有一個值,因爲它顯示在我的日誌中。XML問題,文字沒有顯示android

我的XML看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:background="#e5e5e5" 

    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 



     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="6dp" 
       android:layout_marginRight="6dp" 
       android:layout_marginTop="4dp" 
       android:layout_marginBottom="4dp" 
       android:orientation="vertical" 
       android:background="@drawable/bg_card"> 

       <!-- Card Contents go here --> 


       <ImageView android:id="@+id/breweryImage" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_margin="10dip"/> 


      </LinearLayout > 

     </FrameLayout> 





     <TableLayout 

      android:id="@+id/tableLayout2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center_horizontal" 
      android:shrinkColumns="*" 
      android:stretchColumns="*"> 

      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="6dp" 
        android:layout_marginRight="6dp" 
        android:layout_marginTop="4dp" 
        android:layout_marginBottom="4dp" 
        android:orientation="vertical" 
        android:background="@drawable/bg_card"> 

        <!-- Card Contents go here --> 

        <LinearLayout 
         android:orientation="horizontal" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 

         <TableRow 
          android:id="@+id/tableStatTitles" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 

          android:padding="5dip" > 

          <TextView 
           android:id="@+id/year" 
           android:text="Year Est." 
           android:gravity="center" 
           android:textStyle = "bold" 
           android:textSize="10sp" 
           android:layout_weight="1" 

           ></TextView> 

          <TextView 
           android:id="@+id/bAvg" 
           android:text="Avg" 
           android:gravity="center" 
           android:textStyle = "bold" 
           android:textSize="10sp" 
           android:layout_weight="1" 

           ></TextView> 






         </TableRow> 

         <TableRow 
          android:id="@+id/tableStat" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 

          android:padding="5dip" > 

          <TextView 
           android:id="@+id/yearEnter" 
           android:text="" 
           android:gravity="center" 
           android:textSize="15sp" 
           android:layout_width="wrap_content" 
           ></TextView> 

          <TextView 
           android:id="@+id/avgEnter" 
           android:text="" 
           android:gravity="center" 
           android:textSize="15sp" 
           android:layout_width="wrap_content" 
           ></TextView> 




         </TableRow> 

        </LinearLayout> 


       </LinearLayout > 

      </FrameLayout> 





     </TableLayout> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="6dp" 
       android:layout_marginRight="6dp" 
       android:layout_marginTop="4dp" 
       android:layout_marginBottom="4dp" 
       android:orientation="vertical" 
       android:background="@drawable/bg_card"> 

       <!-- Card Contents go here --> 
       <TextView 
        android:id="@+id/beerDescriptionTitle2" 
        android:textStyle = "bold" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:ems="10" 
        android:textSize="15sp" 
        android:text="Description:" 
        android:padding="5dip" 
        ></TextView> 

       <TextView 
        android:id="@+id/breweryDescription" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:ems="10" 
        android:textSize="15sp" 
        android:padding="5dip" 

        ></TextView> 





      </LinearLayout > 

     </FrameLayout> 




    </LinearLayout> 
</ScrollView> 

其加載的數據看起來像這樣我的異步任務:

public class GetBreweryDataJSON extends AsyncTask<String, Void, String> { 

    Context c; 
    private ProgressDialog Dialog; 

    public GetBreweryDataJSON(Context context) 
    { 
     c = context; 
     Dialog = new ProgressDialog(c); 
    } 

    @Override 
    protected String doInBackground(String... arg0) { 
     // TODO Auto-generated method stub 
     return readJSONFeed(arg0[0]); 
    } 

    protected void onPreExecute() { 
     Dialog.setMessage("Getting brewery information"); 

     Dialog.setTitle("Loading"); 
     Dialog.setCancelable(false); 
     Dialog.show(); 
    } 

    protected void onPostExecute(String result){ 
     //decode json here 
     try{ 

      Log.d("brewery", "in try"); 
      JSONObject o = new JSONObject(result); 

      Log.d("brewery", result); 


      //String name = getName(o); 
      //String description = getDescription(o); 
      //String year = getYear(o); 
      //String icon = getIcon(o); 

      String name = o.getString("name"); 
      String description = o.getString("description"); 
      String year = o.getString("year"); 
      String icon = o.getString("picture"); 
      String avg = o .getString("avg"); 




      //set image 
      ImageView im1 = (ImageView) ((Activity) c).findViewById(R.id.breweryImage); 
      ImageDownloadTask imageD = new ImageDownloadTask(im1); 
      imageD.execute(icon); 

      //create text views 
      TextView breweryYear = (TextView) ((Activity) c).findViewById(R.id.yearEnter); 
      TextView breweryAvg = (TextView) ((Activity) c).findViewById(R.id.avgEnter); 
      TextView breweryDescription = (TextView) ((Activity) c).findViewById(R.id.breweryDescription); 

      String yearPrint = ""; 

      year = yearPrint + year; 

      //set text 
      breweryYear.setText(year); 

      Log.d("brewery" , year); 
      Log.d("brewery" , avg); 

      breweryDescription.setText(description); 
      breweryAvg.setText(avg); 


     } 
     catch(Exception e){ 

     } 

     Dialog.dismiss(); 

    } 

    public String getName(JSONObject json){ 
     String holder; 



     try{ 
      holder = json.getJSONObject("data").getString("name"); 

     } catch (JSONException e) { 
      holder = "N/A"; 
     } 



     return holder; 

    } 



    public String getIcon(JSONObject json){ 
     String holder; 



     try{ 
      holder = json.getJSONObject("data").getJSONObject("images").getString("large"); 

     } catch (JSONException e) { 
      holder = "N/A"; 
     } 



     return holder; 

    } 

    public String getDescription(JSONObject json){ 
     String holder; 



     try{ 
      holder = json.getJSONObject("data").getString("description"); 

     } catch (JSONException e) { 
      holder = "N/A"; 
     } 



     return holder; 

    } 


    public String getYear(JSONObject json){ 
     String holder; 



     try{ 
      holder = json.getJSONObject("data").getString("established"); 

     } catch (JSONException e) { 
      holder = "N/A"; 
     } 



     return holder; 

    } 

    public String readJSONFeed(String URL) { 
     StringBuilder stringBuilder = new StringBuilder(); 
     HttpClient httpClient = new DefaultHttpClient(); 
     HttpGet httpGet = new HttpGet(URL); 
     try { 
      HttpResponse response = httpClient.execute(httpGet); 
      StatusLine statusLine = response.getStatusLine(); 
      int statusCode = statusLine.getStatusCode(); 
      if (statusCode == 200) { 
       HttpEntity entity = response.getEntity(); 
       InputStream inputStream = entity.getContent(); 
       BufferedReader reader = new BufferedReader(
         new InputStreamReader(inputStream)); 
       String line; 
       while ((line = reader.readLine()) != null) { 
        stringBuilder.append(line); 
       } 
       inputStream.close(); 
      } else { 
       Log.d("JSON", "Failed to download file"); 
      } 
     } catch (Exception e) { 
      Log.d("readJSONFeed", e.getLocalizedMessage()); 
     } 
     return stringBuilder.toString(); 
    } 

} 

這裏是我得到的截圖:

enter image description here

+0

你可以嘗試添加一個layout_height到文本,或者只是輸入虛擬文本來驗證它是否可見? – reidisaki

回答

1

看起來我忘了用表格標籤打開和關閉我的XML。我有行,但從不啓動表。