0

I have created androidx.appcompat.widget.AppCompatSpinner but extending an android.widget.BaseAdapter class, when tapping on the spinner it does not show up in android higher than 9. It does not show any error, it just does not show the dialog with the options.

class ImageTextAdapter extends android.widget.BaseAdapter{
private ArrayList<String> files;
private Context context;
ImageTextAdapter(ArrayList<String> _files,Context _context){
    this.files=_files;
    this.context=_context;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public Object getItem(int position) {
    return this.files.get(position);
}

@Override
public int getCount() {
    return this.files.size();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout linearL=new android.widget.LinearLayout(this.context);
    ImageView image=new android.widget.ImageView(this.context);
    TextView txt=new android.widget.TextView(this.context);
    linearL.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    linearL.setOrientation(android.widget.LinearLayout.HORIZONTAL);
    linearL.setGravity(android.view.Gravity.CENTER_VERTICAL);
    image.setLayoutParams(new android.view.ViewGroup.LayoutParams(100, 100));
    txt.setText(java.lang.String.valueOf("Item "+position));
    txt.setTextSize(19);
    linearL.addView(image);
    linearL.addView(txt);
    return linearL;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    LinearLayout linearL=new android.widget.LinearLayout(this.context);
    ImageView image=new android.widget.ImageView(this.context);
    TextView txt=new android.widget.TextView(this.context);
    linearL.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    linearL.setOrientation(android.widget.LinearLayout.HORIZONTAL);
    linearL.setGravity(android.view.Gravity.CENTER_VERTICAL);
    image.setLayoutParams(new android.view.ViewGroup.LayoutParams(100, 100));
    txt.setText(java.lang.String.valueOf("Item "+position));
    txt.setTextSize(19);
    linearL.addView(image);
    linearL.addView(txt);
    return linearL;
}

}

ArrayList lista=new ArrayList<>(); for(int i=0;i<100;i++){ lista.add(String.valueOf(Uri.parse("https://static.india.com/wp-content/uploads/2018/09/42-4.jpg"))); }

    androidx.appcompat.widget.AppCompatSpinner spinner=new androidx.appcompat.widget.AppCompatSpinner(getApplicationContext());
    spinner.setId(android.view.View.generateViewId());
    spinner.setLayoutParams(new android.view.ViewGroup.LayoutParams(750, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    // const adaptador: android.widget.ArrayAdapter<any> = new android.widget.ArrayAdapter<any>(Application.android.foregroundActivity, android.R.layout.simple_spinner_item, lista);
    BaseAdapter adapter = new ImageTextAdapter(lista,getApplicationContext());
    spinner.setAdapter(adapter);

    LinearLayout contenedor=findViewById(R.id.contenedor);
    contenedor.addView(spinner);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.