3

I tried all solutions on StackOverflow but it doesn't work. Each ListView item includes a TextView and a CheckBox as described below. The text in TextView shows one line but doesn't marquee. The strange thing is when I include the line "android:ellipsize=marquee", the CheckBox works wrongly. I mean when I touch checkBox A, it checks B or C! If I exclude that line, it runs well but not marquee. Please help, I'm crazy with it in many hours. :(

Figure enter image description here

This is 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"
/>

Code for 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);
    }

}
emeraldhieu
  • 9,380
  • 19
  • 81
  • 139

1 Answers1

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." />

//your text must be more than the width your mentioned.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Ram
  • 1