2011-09-14 17 views
3

我嘗試了所有StackOverflow解決方案,但它不起作用。每個ListView項目都包含一個TextView和一個CheckBox,如下所述。 TextView中的文本顯示一行,但不顯示字幕。奇怪的是,當我包含「android:ellipsize = marquee」這一行時,CheckBox工作不正常。我的意思是當我觸摸checkBox A時,它會檢查B或C!如果我排除這條線,它運行良好,但不是字幕。 請幫忙,我在幾個小時內瘋了。 :(字幕不工作在自定義列表查看

enter image description here

這是textview_checkbox_row.xml

<TextView android:layout_weight="1" 
android:id="@+id/dictionaryName" 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:text="This is sample text."  
android:layout_gravity="center_vertical"  
android:layout_marginLeft="5dip" 
style="@style/DreamTextView" 

android:ellipsize="marquee"  
android:lines="1" 
android:focusable="true" 
android:focusableInTouchMode="true" 
android:singleLine="true" 
android:scrollHorizontally="true" 
android:freezesText="true" 
/>  

<CheckBox android:layout_weight="0" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/dictionaryEnabled"  
android:layout_marginRight="5dip" 
android:layout_marginLeft="5dip"  
android:layout_gravity="center_vertical" 
/> 

代碼ResourceCursorAdapter

public class ChosenDictionaryCheckBoxAdapter extends ResourceCursorAdapter { 
    private final LayoutInflater inflater; 

    public ChosenDictionaryCheckBoxAdapter(final Context context, final Cursor cursor) { 
     super(context, R.layout.textview_checkbox_row, cursor, true); 
     this.inflater = LayoutInflater.from(context); 
    } 

    private static class ViewHolder { 
     private TextView dictName; 
     private CheckBox dictEnabled; 
    } 

    @Override 
    public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { 
     final View view = 
       inflater.inflate(R.layout.textview_checkbox_row, parent, false); 

     // Create view holder and store it. 
     final ViewHolder viewHolder = new ViewHolder(); 
     viewHolder.dictName = (TextView) view.findViewById(R.id.dictionaryName); 
     viewHolder.dictEnabled = 
       (CheckBox) view.findViewById(R.id.dictionaryEnabled); 
     view.setTag(viewHolder); 

     viewHolder.dictEnabled.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { 
       final int dictID = (Integer) buttonView.getTag(); 

       // Update database. 
       final ContentValues value = new ContentValues(); 
       value.put(ChosenModel.ENABLED_COLUMN, isChecked ? 1 : 0); 
       final String where = ChosenModel.ID_COLUMN + " = " + dictID; 

       final SQLiteDatabase database = 
         DatabaseHelper.getDatabase(context); 
       database.update(ChosenModel.TABLE_NAME, value, where, null); 

       // NEED IMPROVE THIS USE // THIS IS NOT GOOD // 
       cursor.requery(); 
      } 
     }); 
     return view; 
    } 

    @Override 
    public void bindView(final View view, final Context context, final Cursor cursor) { 
     final ViewHolder viewHolder = (ViewHolder) view.getTag(); 

     // Populate the elements of list item. 
     viewHolder.dictEnabled.setTag(cursor.getInt(cursor.getColumnIndex(ChosenModel.ID_COLUMN))); 
     viewHolder.dictName.setText(cursor.getString(cursor.getColumnIndex(ChosenModel.DICTIONARY_NAME_COLUMN))); 
     viewHolder.dictEnabled.setChecked(cursor.getInt(cursor.getColumnIndex(ChosenModel.ENABLED_COLUMN)) == 0 
       ? false : true); 
    } 

} 
+0

顯然你沒有焦點。 http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll尋找這個 – Mikooos

+0

剛剛嘗試過,不工作,太奇怪了! – Emerald214

回答

0
<TextView android:layout_width="100px" 
     android:marqueeRepeatLimit="marquee_forever" android:layout_height="wrap_content" 
     android:textColor="#FF55FF" android:lines="1" android:ellipsize="marquee" 
     android:fadingEdge="horizontal" android:scrollHorizontally="true" 
     android:id="@+id/txt" android:text="Hello Ram............... Welcom to ANDROID." /> 

//你的文字必須超過你提到的寬度。

+0

我認爲它在圖像中顯示文本比textview的寬度更多。 – Talha