如何在onActivityResult方法中更新ListView

时间:2019-03-25 20:41:24

标签: android android-activity android-listview android-arrayadapter onactivityresult

我要从另一个活动(在onActivityResult中)返回后,以粗体显示文本来更新ListView项。我发现您必须创建一个新的ArrayAdapter并覆盖getView,但是它不会以粗体显示。

代码如下:


public void onActivityResult(int requestCode,int resultCode,Intent data){
        if(requestCode == 0 && resultCode == Activity.RESULT_OK){
            String grupoEtario = data.getStringExtra("grupoEtario");
            String jaulaDesde = data.getStringExtra("jaulaDesde");
            String jaulaHasta = data.getStringExtra("jaulaHasta");
            gruposEtarios.set(gruposEtarios.indexOf(getResources().getString(R.string.str_spGrupoEtario) + grupoEtario + getResources().getString(R.string.str_lvJaulaDesde) + jaulaDesde + getResources().getString(R.string.str_lvJaulaHasta) + jaulaHasta + getResources().getString(R.string.str_lvAuditoriaNoRealizada)),
                    getResources().getString(R.string.str_spGrupoEtario) + grupoEtario + getResources().getString(R.string.str_lvJaulaDesde) + jaulaDesde + getResources().getString(R.string.str_lvJaulaHasta) + jaulaHasta + getResources().getString(R.string.str_lvAuditoriaRealizada));


            ArrayAdapter adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, gruposEtarios){
                @Override
                public View getView(int position, View convertView, ViewGroup parent){
                    View view = super.getView(position,convertView,parent);

                    TextView item = (TextView) super.getView(position,convertView,parent);

                    item.setTypeface(item.getTypeface(), Typeface.BOLD);

                    return view;


                }
            };

            lvGruposEtarios.setAdapter(adapter);
            adapter.notifyDataSetChanged();

        }

0 个答案:

没有答案