How to change text color of simple list item

后端 未结 12 2107
清酒与你
清酒与你 2020-11-27 04:12

I have an ListActivity and i am displaying one list with:

setListAdapter(new ArrayAdapter(getApplicationContext(),
                android.R.la         


        
12条回答
  •  失恋的感觉
    2020-11-27 04:34

    If you are creating a class that extends an Adapter, you can use parent variable to obtain the context.

    public class MyAdapter extends ArrayAdapter {
    private Context context;
       @Override
       public View getView(int position, View convertView, ViewGroup parent) {
           context = parent.getContext();
           context.getResources().getColor(R.color.red);
           return convertView;
       }
    }
    

    You can do the same with RecyclerView.Adapter, but instead of getview() you will use onCreateViewHolder().

提交回复
热议问题