Home > Mobile >  Android studio inside setAdapter initialization interface
Android studio inside setAdapter initialization interface

Time:09-19

The setAdapter has been an error, always resolve method, it can not find out where the problem is

CodePudding user response:

MainVp is what things

CodePudding user response:

reference 1st floor BDMH response:
mainVp is a what thing
package com. Example. Ty2;

Import android. Content. SharedPreferences;
import android.os.Bundle;
import android.view.View;
The import android. Widget. ImageView;
The import android. Widget. LinearLayout;
The import androidx. Viewpager. Widget. The viewpager;
The import android. Widget. RelativeLayout;

The import androidx. Appcompat. App. AppCompatActivity;
The import androidx. Fragments. App. Fragments;
import java.util.ArrayList;
import java.util.List;

Public class Main2Activity & lt; Adapter> Extends AppCompatActivity implements the View. An OnClickListener {
ImageView addCityIv moreIv;
LinearLayout pointLayout;
RelativeLayout mainVp;
List FragmentList;
List CityList;

List ImgList;
Private SharedPreferences pref.
Private int bgNum;
Private CityFragmentPagerAdapter adapter.


@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main2);
AddCityIv=the findViewById (R.i d.m ain_iv_add);
MoreIv=the findViewById (R.i d.m ain_iv_more);
PointLayout=the findViewById (R.i d.m ain_layout_point);
MainVp=the findViewById (R.i d.m ain_vp);
AddCityIv. SetOnClickListener (this);
MoreIv. SetOnClickListener (this);
FragmentList=new ArrayList<> (a);
CityList=new ArrayList<> (a);
ImgList=new ArrayList<> (a);
If (cityList. The size ()==0) {
CityList. Add (" chongqing ");
}
InitPager ();
Adapter=new CityFragmentPagerAdapter (getSupportFragmentManager (), fragmentList);
MainVp. SetAdapter (adapter);
InitPoint ();
}

Private void initPoint () {

}

Private void initPager () {
for (int i=0; i CityWeatherFragment cwFrag=new CityWeatherFragment ();
Bundle Bundle=new Bundle ();
Bundle. PutString (" city ", cityList) get (I));
CwFrag. SetArguments (bundle);
FragmentList. Add (cwFrag);
}
}

@ Override
Public void onClick (View v) {
The switch (v.g etId ()) {
Case R.i d.m ain_iv_add:

break;
Case R.i d.m ain_iv_more:

break;
}

}
}

CodePudding user response:

reference 1st floor BDMH response:
mainVp is a what thing
I wrote above a RelativeLayout mainVp

CodePudding user response:

I wrote a RelativeLayout in front mainVp

CodePudding user response:

RelativeLayout can have setAdapter about it, you can't mess with, generally listview, recycleview is

CodePudding user response:

reference 5 floor BDMH reply:
RelativeLayout can have setAdapter about it, you can't mess with, generally listview, recycleview is
thank you
  • Related