/* $Id: TANListEntryAdapter.java 20 2010-06-24 06:21:32Z sj1981 $
*
* This file is part of the TANman application for Android.
* http://code.google.com/p/tanman-android/
*
* Copyright 2010 Sven Jacobs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.svenjacobs.tanman;
import android.content.Context;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.StrikethroughSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.svenjacobs.tanman.core.TANListEntry;
import java.util.List;
/**
* Data adapter for TANListEntry's in a ListView.
*
* @author Sven Jacobs
* @see de.svenjacobs.tanman.core.TANListEntry
*/
public class TANListEntryAdapter extends ArrayAdapter<TANListEntry> {
private final LayoutInflater inflater;
public TANListEntryAdapter( final Context context, final int textViewResourceId, final List<TANListEntry> objects ) {
super( context, textViewResourceId, objects );
inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
}
@Override
public View getView( final int position, final View convertView, final ViewGroup parent ) {
final TANListEntry entry = getItem( position );
final TextView textView;
if ( convertView instanceof TextView ) {
textView = (TextView) convertView;
} else {
textView = (TextView) inflater.inflate( R.layout.tan_list_entry_item, parent, false );
}
textView.setText( entry.getValue(), TextView.BufferType.SPANNABLE );
if ( !entry.isValid() ) {
// set the text style to strikethrough
final CharSequence t = textView.getText();
( (Spannable) t ).setSpan( new StrikethroughSpan(), 0, t.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE );
}
return textView;
}
}
|