我正在创建一个没有任何自定义的简单适配器。我只想让微调器中显示的项目来自gettersetter类。我重写了适配器的getview方法,但它给了我指针的地址而不是项目。这是我的代码,以便更好地理解。
UserType users = new ArrayList<>();
users = db.getUsers(groupid);
ArrayAdapter adapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,users){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setText(users.get(position).getUsername());
return view;
}
};
spinner.setAdapter(adapter);
使用此方法,微调器中显示的项目数是正确的,但不显示项目名称。
答案 0 :(得分:0)
BroadcastReceiver
Class2
private BroadcastReceiver updateProfileBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Fire your event
}
};
在onResume()
registerReceiver(updateProfileBroadcast, new IntentFilter("KEY"));
现在在 MainActivity
上触发广播 Intent intent = new Intent("KEY");
getActivity().sendBroadcast(intent);