Array Adapter is not initialized in android

0

Good evening!    I have a problem when trying to call a DialogFragment that presents me with a list already with the fixed values in a String [] array, but when I run the app Fragment is simply not instantiated and the getView method is not called: how the fragmentDialog call is made in Activity:

CurrenciesListFragment list = new CurrenciesListFragment();
            list.show(CurrenciesDetailsActivity.this.getSupportFragmentManager(), "Lista de moedas");

DialogFragment

public class CurrenciesListFragment extends DialogFragment {
//ATRIBUTOS
private ListView lvCoins;
private ArrayAdapter adapter;
private ArrayList<String> lista;

public CurrenciesListFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_currencies_list, container, false);
    this.getDialog().setTitle("Currencies List");

    //INSTANCIANDO OS COMPONENTES
    lista = new ArrayList<>();
    lvCoins = (ListView) view.findViewById(R.id.lv_currencies);

    //Montando a lista
    adapter = new CurrenciesAdapter(getActivity(), lista);
    lvCoins.setAdapter(adapter);

    return view;

}

}

The Adapter:

public class CurrenciesAdapter extends ArrayAdapter<String> {
//ATRIBUTOS
private Context context;
private ArrayList<String> obj1;
private String[] siglas = {"BTC", "ETH", "XRP", "TRX", "BCH", "LTC", "SNGLS", "EOS", "CRW", "BTG", "GNT",
        "XMR", "MXT", "ZEC", "DCR", "DASH", "OMG", "BNB", "BRZX", "PRSP", "EPC"};

private String[] coins = {"Bitcoin", "Etherum", "Ripple", "Tron", "Bitcoin Cash", "Litecoin", "SingularDTV",
        "EOS", "Crown", "Bitcoin Gold", "Golem", "Monero", "Martex Coin", "ZCash",
        "Decred", "Dash", "OmiseGO", "BinanceCoin", "Braziliex Token", "Prosper", "EpaCoin"};

public CurrenciesAdapter(@NonNull Context c, ArrayList<String> obj) {
    super(c, 0);
    this.context = c;
    this.obj1 = obj;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = null;

    //CRIANDO A LISTA DE MOEDAS
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

    //Montando a view a partir do xml
    view = inflater.inflate(R.layout.list_currencies, parent, false);

    //RECUPERANDO OS COMPONENTES
    TextView tvSigla = view.findViewById(R.id.tv_sigla);
    TextView tvCoin = view.findViewById(R.id.tv_crypto_name);

    //REALIZANDO O LOOP PARA PRENCHER OS CAMPOS
    if (siglas.length == coins.length){

        for (int i = 0; i < siglas.length; i++){
            tvSigla.setText(siglas[i].toString());
            tvCoin.setText(coins[i].toString());
        }

    } else {
        Log.i("Erro Matrizes", "As matrizes das moedas estão diferentes!");
    }

    return view;
}

}

fragmentLayout.xml

<?xml version="1.0" encoding="utf-8"?>

<ListView
    android:id="@+id/lv_currencies"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</FrameLayout>

list called in adapter.xml

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/tv_sigla"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="btc"
    android:textSize="@dimen/tv_sigla_list"
    android:layout_marginTop="@dimen/mrg_list_crypto"
    android:layout_marginLeft="@dimen/mrg_list_crypto"
    android:layout_marginBottom="@dimen/mrg_list_crypto"/>

<TextView
    android:id="@+id/tv_crypto_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@+id/tv_sigla"
    android:text="Bitcoin"
    android:textSize="@dimen/tv_crypto_list"
    android:layout_toRightOf="@+id/tv_sigla"
    android:layout_marginTop="@dimen/mrg_list_crypto_top"
    android:layout_marginLeft="@dimen/mrg_list_crypto"
    android:layout_marginBottom="@dimen/mrg_list_crypto"/>

  </RelativeLayout>

In this case the problem I noticed is that the Adapter does not call the onGetView method, but I could not figure out why.

    
asked by anonymous 26.04.2018 / 02:37

0 answers