在ListView中设置特定项目的样式

时间:2015-11-13 02:13:57

标签: android listview

如何为ListView中的特定项目设置样式?例如,让我们说
if(text in list view.equals("ABC")),然后ABC应为bold, have a size of 16sp等。我正在从String数组中创建此ListView

这是我的代码:

public class IngSearch extends AppCompatActivity implements AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener {

    ListView lv;
    String list[] = {"123", "QAZ", ""edc", "ABC"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ing_search); 
        lv = (ListView) findViewById(R.id.list1);
        lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));

在此列表中,我想将这样的样式应用于ABC

<style name="abcStyle">
    <item name = "android:textSize">24sp</item>
    <item name="android:textColor">#000</item>
</style>

由于

1 个答案:

答案 0 :(得分:1)

我认为这是解决方案 首先,您需要自定义getView(...)然后在 public class ListViewAdapter extends BaseAdapter { @Override public int getCount() { ... } @Override public codeLearnChapter getItem(int arg0) { ... } @Override public long getItemId(int arg0) { ... } @Override public View getView(int arg0, View arg1, ViewGroup arg2) { ... TextView textViewTitle = (TextView) findViewById(R.id.text_view_title); if(your condition){ textViewTitle.setTextAppearance(this, R.style.abcStyle); // change your textview style here }else if(...){ textViewTitle.setTextAppearance(// another style ); }else{ textViewTitle.setTextAppearance(// another style ); } } } 内,您可以为每个特定的文本视图设置样式

childScrollView.setNestedScrollingEnabled(false)

希望这个帮助