如何为Android L-preview导入RecyclerView
正在尝试使用支持库中的新RecyclerView。我使用SDK管理器下载了支持库的20更新 我已经将jar文件添加到了libs文件夹中,并添加到了构建路径中,使用RecyclerView没有什么好运气 还尝试使用gradle依赖项,根据-不确定这是否是查看的正确位置-此页面与AndroidTV更相关:如何为Android L-preview导入RecyclerView,android,gradle,android-5.0-lollipop,android-recyclerview,Android,Gradle,Android 5.0 Lollipop,Android Recyclerview,正在尝试使用支持库中的新RecyclerView。我使用SDK管理器下载了支持库的20更新 我已经将jar文件添加到了libs文件夹中,并添加到了构建路径中,使用RecyclerView没有什么好运气 还尝试使用gradle依赖项,根据-不确定这是否是查看的正确位置-此页面与AndroidTV更相关: com.android.support:recyclerview-v7:20.0.+ 无法渐变同步项目 有什么想法吗?这对我很有用: compile 'com.android.support:
com.android.support:recyclerview-v7:20.0.+
无法渐变同步项目
有什么想法吗?这对我很有用:
compile 'com.android.support:recyclerview-v7:21.0.0-rc1'
我明白了
您必须添加以下渐变依赖项:
compile 'com.android.support:recyclerview-v7:+'
我编译的另一个问题是compileSdkVersion
。显然,您必须根据android-L
您的build.gradle文件应如下所示:
apply plugin: 'android'
android {
compileSdkVersion 'android-L'
buildToolsVersion '19.1.0'
[...]
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:+'
}
我使用了一个小技巧在旧设备上使用RecyclerView。我只是进入我当地的m2存储库,拿起RecyclerView源文件并将它们放入我的项目中 您可以在此处找到源代码: \extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1\recyclerview-v7-21.0.0-rc1-sources.jar
将RecyclerView导入项目的一个好方法是。这是一个开源库,它删除了RecyclerView以使其安全且易于实现。你可以阅读作者的博客文章 在代码中添加以下行作为渐变依赖项:
dependencies {
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+@aar'
}
有关如何引入渐变依赖项的更多信息:
波斯尼亚你说得对,这很烦人。Gradle看起来很复杂,但它非常强大和灵活。一切都是用groovy语言完成的,学习gradle系统就是学习另一种语言,这样你就可以构建你的Android应用程序。现在很痛,但从长远来看你会喜欢的
查看同一应用程序的build.gradle。它执行以下操作的地方是将lib引入模块的地方(也称为示例应用程序)
请注意此文件的位置。这不是顶级build.gradle
因为lib源代码在同一个项目中,所以它可以通过简单的
':library'
来实现这一点。exclude
告诉lib使用示例应用程序的支持v4。这不是必要的,但却是个好主意。您的项目中没有或不想有lib的源代码,因此您必须指向internet。在模块/应用程序的build.gradle中,您可以将此答案开头的那一行放在同一位置。或者,如果遵循示例,您可以将':library'
替换为'com.twodoasters.recycleServiceWLIB:library:1.0.+@aar'
,并使用排除项。其他答案对我不起作用。我不得不加上这句话:
编译'com.android.support:recyclerview-v7:21.0.0'
我已经创建了使用以下行,这对我的作品
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
对于AndroidX
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
有关完整教程,请参见
在Android Studio中,导入并不像人们希望的那样直观。尝试导入此位,看看它有多大帮助 我面前的步伐只差一步 更改build.gradle(模块:app)并添加以下依赖项后: 编译'com.android.support:cardview-v7:21.0.+'
编译'com.android.support:recyclerview-v7:21.0.+' (如有必要,添加cardview) 然后必须转到构建>清理项目以消除任何错误
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
}
只需在build.gradle文件中创建上面的依赖项,这对我很有用。在我的例子中,我通过将
编译'com.android.support:recyclerview-v7:22.0.0'
作为依赖项添加到我的gradle构建中来修复它
(Android studio v.1.2.1.1和所有sdk都已更新。)
当代码更新得如此之快,IDE无法跟踪它们,而您必须手动修复它们时,这真的很烦人,浪费时间和资源
但是,它终于可以工作了。如果您已经编译了SDK版本22.2.0,那么在下面添加对recycler view的依赖项和对cardview的额外支持 //用于在目录库中包含所有库
编译文件树(包括:['*.jar'],目录:“libs”)
//支持appcompat
编译'com.android.support:appcompat-v7:22.2.0'
//包括谷歌支持设计(它可以实现2.3及更高版本的材料设计主题)
`编译'com.android.support:design:22.2.0'
要添加回收器视图,请使用以下依赖项
编译'com.android.support:recyclerview-v7:22.2.0'
然后单击Build->rebuild project,您就完成了。如果有人仍然存在此问题-您不必更改
compileSdkVersion
,这完全违背了支持库的目的
相反,请在gradle.build
文件中使用这些选项:
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:palette-v7:+'`
现在可以通过在app gradle中编译设计依赖项来添加RecyclerView:
dependencies {
...
compile 'com.android.support:design:24.0.0'
}
这对我有用。
试试看。在
build.gradle
中包含依赖项,并将项目与gradle
文件同步
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//include the revision no, i.e 25.1.1
implementation 'com.android.support:recyclerview-v7:25.1.1'
}
包括修订版(此处为25.1.1)以避免不可预测的版本,请选中-转到活动\u main.xml中的设计部分 -在拖放托盘中,选择“应用压缩性” -在应用压缩性中选择回收视图 -选择时,将出现一个对话框,单击“确定”
-你的项目应用程序:gradle将自动更新我使用过这一个正在为我工作。有一件事需要考虑的是:<代码> AppCupAt/Cuth>您正在使用的版本。我正在使用appcompat-v7:26.+所以这对我来说很有用
implementation 'com.android.support:recyclerview-v7:26.+'
我的依赖
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
//RecyclerView dependency
compile 'com.android.support:recyclerview-v7:25.1.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
我只添加了编译'com.android.support:recyclerview-v7:25.1.0'。重要的是增加回收
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//include the revision no, i.e 25.1.1
implementation 'com.android.support:recyclerview-v7:25.1.1'
}
implementation 'com.android.support:recyclerview-v7:26.+'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
//RecyclerView dependency
compile 'com.android.support:recyclerview-v7:25.1.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
<uses-permission android:name="android.permission.INTERNET" >
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile ('com.squareup.retrofit2:converter-simplexml:2.1.0'){
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
exclude group: 'xpp3', module: 'xpp3'
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
public class MainActivity extends AppCompatActivity {
private BreakfastMenu breakfastMenu;
List<BreakfastMenu> list;
TextView responseText;
APIInterface apiInterface;
String name;
String price;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
responseText=(TextView)findViewById(R.id.reponseText);
apiInterface = APIClient.getClient().create(APIInterface.class);
/**
GET List Resources
**/
Call<BreakfastMenu> call = apiInterface.getBreakfastMenu();
call.enqueue(new Callback<BreakfastMenu>() {
@Override
public void onResponse(Call<BreakfastMenu> call, Response<BreakfastMenu> response) {
Log.d("TAG", response.code() + "");
String displayResponse = "";
BreakfastMenu resource = response.body();
System.out.println(displayResponse+"display response ");
for (Food food : resource.getFoodList())
{
name=food.getName();
price=food.getPrice();
System.out.println(name+price+"=========================================");
displayResponse += food.getName() + " " + food.getPrice()+"\n"+"\n";
Toast.makeText(MainActivity.this,name+price,Toast.LENGTH_LONG).show();
}
responseText.setText(displayResponse);
}
@Override
public void onFailure(Call<BreakfastMenu> call, Throwable t) {
call.cancel();
}
});
}
}
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
class APIClient {
private static Retrofit retrofit = null;
static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl("https://www.w3schools.com/")
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
return retrofit;
}
}
enter code here
Make APIInterface.java
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
interface APIInterface {
@GET("xml/simple.xml")
@Headers({"Accept: application/xml",
"User-Agent: Retrofit-Sample-App"})
Call<BreakfastMenu> getBreakfastMenu();
}
In BreakfastMenu.java
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.util.List;
@Root(name = "breakfast_menu")
public class BreakfastMenu
{
@ElementList(inline = true)
private List<Food> foodList;
public BreakfastMenu()
{
}
public List<Food> getFoodList()
{
return foodList;
}
public void setFoodList(List<Food> foodList)
{
this.foodList = foodList;
}
}
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
@Root(name = "food")
public class Food
{
@Element(name = "name")
private String name;
@Element(name = "price")
private String price;
@Element(name = "description")
private String description;
@Element(name = "calories")
private String calories;
public Food()
{
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPrice()
{
return price;
}
public void setPrice(String price)
{
this.price = price;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getCalories()
{
return calories;
}
public void setCalories(String calories)
{
this.calories = calories;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/reponseText"
android:layout_width="match_parent"
android:layout_height="600dp"
/>
</Linear Layout>
compile 'com.android.support:recyclerview-v7:+'
implementation 'com.android.support:recyclerview-v7:+'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'