N
N
Nikita K2020-04-05 15:10:37
Android
Nikita K, 2020-04-05 15:10:37

The android.support.v7 library is not imported, what should I do?

I tried the methods that I found on the toaster, stack, cyberforum. Nothing helped, I don't know what's wrong.
This is my build..gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.+"

    defaultConfig {
        applicationId "com.your.appname"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation ('android.arch.core:runtime:+') {
        force = true
    }

    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:19.+'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}


This is my MainActivity, everything is red here, all libraries where there is v7 are not imported and are gray:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

     private RecyclerView recyclerView;
     private RecyclerView.Adapter adapter;
     private RecyclerView.LayoutManager layoutManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ArrayList<RecyclerViewItem> recyclerViewItems = new ArrayList<>();
        recyclerViewItems.add(new RecyclerViewItem(R.drawable.ic_mood_bad_black_24dp, "Happy", "Live is fan" ));
        recyclerViewItems.add(new RecyclerViewItem(R.drawable.ic_mood_black_24dp, "Happy not", "Live is fan" ));

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setHasFixedSize(true);
        adapter = new RecyclerViewAdapter(recyclerViewItems);
        layoutManager = new LinearLayoutManager(this);

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(layoutManager);

    }
}


PS: I copied this build.gradle from the cyberforum, neither mine nor this one worked

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dinasars, 2020-04-06
@Dinasars

As I understand it, the problem with the display of recyclerView, and on the Internet everyone suggests connecting the old library. Here I have a new library. The code itself on Kotlin
RecyclerView is spinning in the
build gradle fragment:

implementation 'androidx.recyclerview:recyclerview:1.1.0'

xml fragment:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/constraintLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

code in snippet:
import androidx.recyclerview.widget.RecyclerView


val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView1)
        recyclerView.layoutManager = LinearLayoutManager(activity)
        recyclerView.adapter = MyAdapter(list)

Adapter in fragment:
class MyAdapter(private val values: MutableList<String>) : RecyclerView.Adapter<Adapter.ViewHolder>() {

        override fun getItemCount() = values.size

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val itemView = LayoutInflater.from(parent.context).inflate(R.layout.list_two, parent, false)
            return ViewHolder(itemView)
        }

        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            holder.textView?.text = values[position].toString()
            holder.textView?.setOnClickListener {
                Toast.makeText(it.context, values[position], Toast.LENGTH_LONG).show()
            }
        }

        class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
            var textView: TextView? = null
            init {
                textView = itemView?.findViewById(R.id.textView4)
            }
        }
    }

list_two
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_weight="1"
        android:maxWidth="40dp"
        android:maxHeight="40dp"
        android:minWidth="40dp"
        android:minHeight="40dp"
        app:srcCompat="@drawable/temporary" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="1dp"
        android:layout_weight="100"
        android:text="TextView"
        android:textColor="#000000"
        android:textSize="16sp" />

</LinearLayout>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question