问题描述
当应用程序启动时使用onCreateView填充列表(白色文本)时附加了2张照片,另一张是调用SetList()方法时的另一张照片
Attached are 2 photos one when the list is populated using the onCreateView when the app starts(white text) and the other is whenever the SetList() method is called
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ListView lv = (ListView) rootView.findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
lv.setAdapter(adapter);
return rootView;
}
public void SetList()
{
ListView lv = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,Logs);
lv.setAdapter(adapter);
}
推荐答案
通过更改$ b解决了问题$ b ArrayAdapter< String> adapter = new ArrayAdapter< String>(((MainActivity)getActivity())。getApplicationContext(),android.R.layout.simple_list_item_1,((MainActivity)getActivity())。Logs);
Problem solved by changingArrayAdapter<String> adapter = new ArrayAdapter<String>(((MainActivity)getActivity()).getApplicationContext(), android.R.layout.simple_list_item_1,((MainActivity)getActivity()).Logs);
到
ArrayAdapter< String> adapter = new ArrayAdapter< String>(((MainActivity)getActivity())。getBaseContext(),android.R.layout.simple_list_item_1,((MainActivity)getActivity())。Logs);
似乎由于某种原因((MainActivity)getActivity())。getApplicationContext()
返回不同的默认文本颜色比((MainActivity)getActivity())。getBaseContext()
it seems like for some reason ((MainActivity)getActivity()).getApplicationContext()
returns a different default text color than ((MainActivity)getActivity()).getBaseContext()
这篇关于Android Listview文本颜色白色onCreateView(而不是黑色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!