I am setting adapter to listview and the text color is showing white. How can i change the text color without making my own row item layout? Below is my code which is throwing this error-
01-15 16:33:40.197: E/AndroidRuntime(6088): java.lang.NullPointerException
01-15 16:33:40.197: E/AndroidRuntime(6088): at com.mb.pyramid.ui.fragment.DeviceListFragment$2.getView(DeviceListFragment.java:73)
My code :
mBTAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView)view.findViewById(android.R.layout.simple_list_item_1);
textView.setTextColor(Color.BLACK);
return view;
}
};
android.R.layout.simple_list_item_1
contains only a TextView
. In this case you can cast the return value of super.getView(...)
avoiding the findViewById
:
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(Color.BLACK);
return textView;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.