简体   繁体   中英

Cannot infer type arguments for ArrayAdapter<> in Android

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SeekBar seekBar=findViewById(R.id.seekBar);
    seekBar.setMax(20);
    seekBar.setProgress(10);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            final ArrayList<String> tables = new ArrayList<>();
            final ArrayAdapter<String> adaptor = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,tables);

ArrayAdapter(this,android.R.layout.simple_list_item_1,tables) ;

This line is giving error of cannot infer type argument. Any suggestions ?

I am trying to add data to ArrayList and then that to ListView.

Use YourActivityName.this instead of this.

 final ArrayAdapter<String> adaptor = new ArrayAdapter<String>(YourActivityName.this,android.R.layout.simple_list_item_1,tables);

Let me know if still does not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM