I wanted to program fragments for my chat but I always get the same error message. on the internet, I read that it should have to do with the "import" and the "import android.support.v4.app.Fragment;" but that does not work for me.
Added the packet also in the build.gradle (app) does not work ..
My Android Studio version is 3.3 Canary 5.
I hope you can solve my problem maybe, many thanks!
TabsPagerAdapter
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import android.support.v4.app.Fragment;
class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
RequestsFragment requestsFragment = new RequestsFragment();
return requestsFragment;
case 1:
ChatsFragment chatsFragment = new ChatsFragment();
return chatsFragment;
case 2:
FriendsFragment friendsFragment = new FriendsFragment();
return friendsFragment;
default:
return null;
}
}
@Override
public int getCount()
{
return 3;
}
public CharSequence getPageTitle(int position)
{
switch (position)
{
case 0:
return "Requests";
case 1:
return "Chats";
case 2:
return "Friends";
default:
return null;
}
}
}
build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.nexsis.entwicklung.swapv12"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:support-v4:28'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28'
implementation 'com.android.support:design:28'
implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
apply plugin: 'com.google.gms.google-services'
your imports seem to collide ...
down-grading, as other answers suggest does not appear to be the solution. see the artifact mappings, which explain how to chance the
build.gradle; for example,com.android.support:support-fragmentwould need to be replaced there withandroidx.fragment:fragment, so that the import would become known.