0

私はAndroidの初心者です。ListView でいくつかの行を動的に強調表示したいと思います。たとえば、数字のリストを印刷する場合、特定の条件を満たす数値を含む行を太字にしたいと考えています。

カスタムアダプターを使用しています。これどうやってするの?

4

2 に答える 2

1

/res/values フォルダに style.xml などのスタイルを作成する必要があります。

<resources>
    <style name="textbold" parent="@android:style/TextAppearance">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textstyle">bold</item>
    </style>
</resources>

カスタム リストビュー アダプタで setTextAppearance() メソッドを使用します。

@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
    View result = getLayoutInflater().inflate(xml_resource, null);
    TextView tx = (TextView) result.findViewById(R.id.text-view-id);

    if(condition == true)
    {
        tx.setTextAppearance(context, R.style.your-style-name);
    }
    else
    {
        //something else
    }
    ........
}
于 2013-07-21T12:46:46.283 に答える