2013-08-25 54 views
0

這些是我的代碼,我在AsyncTask onPostExcute函數中運行這些代碼。TextView setText引發應用程序掛起

LayoutInflater inflater =LayoutInflater.from(this.context); 
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.custom_info_window, null, false); 
    layout.addView(layout); 
    View view = (View) layout; 

    ((ImageView) view.findViewById(R.id.badge)).setImageResource(badge); 
    String title = marker.getTitle(); 
    TextView titleUi = ((TextView) view.findViewById(R.id.title)); 
    titleUi.setText(title); 

當應用程序運行到這裏,沒有錯誤和應對

這裏是我的xml文件名爲custom_info_window.xml內容

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<ImageView 
    android:id="@+id/badge" 
    android:contentDescription="@string/info_window" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="5dp" 
    android:adjustViewBounds="true" > 
</ImageView> 

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

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textColor="#ff000000" 
     android:textSize="14sp" 
     android:textStyle="bold" /> 
    <TextView 
     android:id="@+id/snippet" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textColor="#ff7f7f7f" 
     android:textSize="14sp" /> 
</LinearLayout> 

我嘗試dispaly這個視圖在AsyncTask執行後Mainactivity的子視圖 但它不起作用。 沒有錯誤或警告。 我在行「titleUi.setText(」1312「)」設置斷點,當應用程序運行到這裏時,沒有響應。它看起來像死了。

任何人都可以幫助我嗎? 謝謝提前。

回答

1

這裏嘗試後整個的AsyncTask代碼。我認爲故障是在你的代碼的以下部分:

LayoutInflater inflater =LayoutInflater.from(this.context); 
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.custom_info_window, null, false); 
layout.addView(layout); 
View view = (View) layout; 

試試這個,

LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.custom_info_window, null); 
    ((ImageView) view.findViewById(R.id.badge)).setImageResource(badge); 
    String title = marker.getTitle(); 
    TextView titleUi = ((TextView) view.findViewById(R.id.title)); 
    titleUi.setText(title); 
+0

請贊成票,並接受我的回答是否能解決您的問題,讓任何人都知道問題已解決。樂於幫助! – 2013-08-26 04:08:47

0

轉到DEBUGGER試圖找出進一步的情況。

或使用:

Log.e("Log Title","message");