RecyclerView
-
مطالب مشابه
-
توسط sina_f2000
با سلام و خسته نباشید خدمت اساتید بزرگوار
یه درخواست داشتم امیدوارم کمکم کنید
کد ارسال تصاویر یک دایرکتوری از قبل مشخص شده به سمت سرور میخاستم اگه لطف کنید کدش به همراه فایل php بفرستید ممنون میشم
-
توسط scientific
سلام وقت بخیر
سلام من دو تا ریسایکلرویو تعریف کردم که هر کدوم آیتمهای مخصوص خودشون رو دارن ، و از یک لیوت نمونه و از یک آداپتر برای هر دو استفاده کردم،
حالا برای رویداد کلیک آیتم ها به مشکل بر خوردم
چون طبیعتا پوزیشن آیتم ها در هر دو ریسایکلرویو یکسان هست؛ مثلا پوزیشن آیتم اول ، در هردو ریسایکلرویو صفر هست و وقتی میگم اگر روی آیتم صفر کلیک شد برو به اکتیویتی دوم
برای هر دو ریسایکلرویو همین اتفاق میفته؛
((یعنی وقتی روی اولین آیتم در ریسایکلرویوی اولم کلیک میکنم میره به اکتیویتی دو و وقتی روی اولین آیتم از ریسایکلرویوی دوم هم کلیک میکنم بازم میره به اکتیویتی دو))
راهنماییم کنید ممنون میشم
کلاس آداپتر:
package com.donyaeayandeh.itroducingdonyaeayandehinstitute; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.List; public class AdapterRecyclerView extends RecyclerView.Adapter<CourseEducationViewHolder> { List<CourseModel> list; public AdapterRecyclerView(List<CourseModel> courseModelslist) { this.list = courseModelslist; } @NonNull @Override public CourseEducationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.course_education_list_item,parent,false); return new CourseEducationViewHolder(view); } @Override public void onBindViewHolder(@NonNull final CourseEducationViewHolder holder, final int position) { // fill items from List: holder.course_education_image.setImageResource(list.get(position).getCuorse_education_icon()); holder.course_education_txt.setText(list.get(position).getCourse_education_title()); // Click recyclerView Items: holder.itemView.setOnClickListener(new View.OnClickListener() { Intent intent; @Override public void onClick(View view) { Toast.makeText(view.getContext(),"The Item Clicked is: " +holder.getLayoutPosition(),Toast.LENGTH_SHORT).show(); if(position==0){ intent=new Intent(view.getContext(),Cheshmandaz_Dore_Info.class); view.getContext().startActivity(intent); } } }); } @Override public int getItemCount() { return list.size(); } } ممنون میشم جواب بدید
-
توسط scientific
سلام وقت بخیر
من در یکی از لیوت ها که مربوط به لیوت آیتم هام میشه از متریال کاردویو استفاده کردم و برنامه م به محض اجرا بسته میشه...
وقتی از خود کاردویو ی Androidx استفاده می کنم برنامه اجرا میشه و آیتم ها رو داخل ریسایکلرویو نشون میده.
توی لاگ کت به کلاس materialCardview اندروید خطا می گیره بازش کردم دیدم R ها رو نمیشناسه :
(عکس خود کلاسش رو هم پیوست کردم.)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78) at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:128) at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:118) ... 66 more دپندسی متریال رو اضافه می کنم ولی بازم تاثیری نداره:
کل دپندنسی ها:
dependencies { def nav_version = "1.0.0-alpha06" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "androidx.appcompat:appcompat:${var}" implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13-beta-3' androidTestImplementation 'androidx.test:runner:1.3.0-alpha02' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02' implementation 'me.relex:circleindicator:2.1.2' implementation 'com.google.android.material:material:1.1.0-alpha08' implementation 'de.hdodenhof:circleimageview:3.0.0' implementation 'com.github.bumptech.glide:glide:4.7.1' implementation 'com.android.support:appcompat-v7:29.0.0' //implementation 'androidx.appcompat.app.ActionBarDrawerToggle' //implementation 'androidx.appcompat.app' //implementation 'androidx.cardview:cardview:1.0.0' //implementation 'com.android.support:cardview-v7:29.0.0' //implementation 'com.android.support:design:28.0.0' implementation "android.arch.navigation:navigation-fragment:$nav_version" implementation "android.arch.navigation:navigation-ui:$nav_version" implementation 'androidx.drawerlayout:drawerlayout:1.0.0' } لیوتی که دراون از متریال کاردویو استفاده کردم (لیوت آیتم ها) :
<?xml version="1.0" encoding="utf-8"?> <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" app:contentPadding="8dp" app:cardElevation="4dp" android:layout_marginTop="5dp" android:background="@color/green5"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/course_education_icon" android:layout_width="@dimen/circle_whidth_height" android:layout_height="44dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/course_education_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:layout_marginEnd="8dp" android:textSize="@dimen/textSize_nav_info" android:textColor="@color/colorPrimaryDark" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/course_education_icon" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </com.google.android.material.card.MaterialCardView> کلاس مربوط به متریال کاردویو خود اندروید رو هم پیوست کردم.
ممنون میشم راهنمایی کنید چطور می تونم از متریال کاردویو استفاده کنم؟
-
توسط scientific
سلام وقت بخیر
من در یکی از لیوت ها که مربوط به لیوت آیتم هام میشه از متریال کاردویو استفاده کردم و برنامه م به محض اجرا بسته میشه...
وقتی از خود کاردویو اندروید ایکس استفاده می کنم برنامه اجرا میشه و آیتم ها رو داخل ریسایکلرویو نشون میده
توی لاگ کت به کلاس materialCardview اندروید خطا می گیره بازش کردم دیدم R ها رو نمیشناسه :
(عکس خود کلاسش رو هم پیوست کردم.)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78) at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:128) at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:118) ... 66 more
دپندسی متریال رو اضافه می کنم ولی بازم تاثیری نداره:
dependencies { def nav_version = "1.0.0-alpha06" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "androidx.appcompat:appcompat:${var}" implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13-beta-3' androidTestImplementation 'androidx.test:runner:1.3.0-alpha02' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02' implementation 'me.relex:circleindicator:2.1.2' implementation 'com.google.android.material:material:1.1.0-alpha08' implementation 'de.hdodenhof:circleimageview:3.0.0' implementation 'com.github.bumptech.glide:glide:4.7.1' implementation 'com.android.support:appcompat-v7:29.0.0' //implementation 'androidx.appcompat.app.ActionBarDrawerToggle' //implementation 'androidx.appcompat.app' //implementation 'androidx.cardview:cardview:1.0.0' //implementation 'com.android.support:cardview-v7:29.0.0' //implementation 'com.android.support:design:28.0.0' implementation "android.arch.navigation:navigation-fragment:$nav_version" implementation "android.arch.navigation:navigation-ui:$nav_version" implementation 'androidx.drawerlayout:drawerlayout:1.0.0' } این لیوتی که دراون از متریال کاردویو استفاده کردم (لیوت آیتم ها):
<?xml version="1.0" encoding="utf-8"?> <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" app:contentPadding="8dp" app:cardElevation="4dp" android:layout_marginTop="5dp" android:background="@color/green5"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/course_education_icon" android:layout_width="@dimen/circle_whidth_height" android:layout_height="44dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/course_education_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:layout_marginEnd="8dp" android:textSize="@dimen/textSize_nav_info" android:textColor="@color/colorPrimaryDark" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/course_education_icon" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </com.google.android.material.card.MaterialCardView> کلاس مربوط به متریال کاردویو خود اندروید رو هم پیوست کردم.
ممنون میشم راهنمایی کنید چطور می تونم از متریال کاردویو استفاده کنم؟
-
توسط scientific
سلام ،
من وقتی در MainActivity یه آبجکت از کلاس مدلم می سازم و داده هام رو به پارامترهای constructor اش می فرستم تا در کلاس مدل ذخیره بشه ،
و هم زمان اون اطلاعات رو داخل یک لیست از کلاس مدل هم ذخیره می کنم، برنامه م به محض اجرا بسته میشه
مگر این که کد مربوط به این کار رو کامنت کنم:
courseModelList.add(new CourseModel(image,s)); یا این که باید کد مربوط به "ست شدن آداپتر به ریسایکلرویو" رو کامنت کنم تا برنامه اجرا بشه:
recyclerView_course_main.setAdapter(adapterRecyclerView); --------------------------------------------------------------------------------------------------------------------------
هرکار می کنم ریسایکلرویو رو توی برنامه م نمیتونم نشون بدم
بریک پوینت هم گذاشتم و لاگ کت رو چک کردم ولی بازم نتونستم ایرادش رو برطرف کنم
عکسهایی از کد ها و اجرای خط به خط رو میزارم اگه راهنمایی کنید ممنون میشم:
1- کلاس MainActivity متد مربوط به پر کردن لیست آرایه و ست کردن آداپتر:
private void setupRecyclerView() { courseModelList.add(new CourseModel(image,s)); courseModelList.add(new CourseModel(image,s)); recyclerView_course_main = findViewById(R.id.recyclerView_coursemain); adapterRecyclerView = new AdapterRecyclerView(courseModelList); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView_course_main.setLayoutManager(linearLayoutManager); recyclerView_course_main.setAdapter(adapterRecyclerView); } 2- کلاس آداپتر:
3- کلاس مدل:
public class CourseModel { private int cuorse_education_icon; private String course_education_title; public CourseModel(int cuorse_education_icon, String course_education_title) { this.cuorse_education_icon = cuorse_education_icon; this.course_education_title = course_education_title; } public int getCuorse_education_icon() { return cuorse_education_icon; } public String getCourse_education_title() { return course_education_title; } 4- کلاس ViewHolder
import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.donyaeayandeh.itroducingdonyaeayandehinstitute.R; import de.hdodenhof.circleimageview.CircleImageView; public class CourseEducationViewHolder extends RecyclerView.ViewHolder { public CircleImageView course_education_image; public TextView course_education_txt; public CourseEducationViewHolder(@NonNull View itemView) { super(itemView); course_education_image = itemView.findViewById(R.id.course_education_icon); course_education_txt= itemView.findViewById(R.id.course_education_txt); } }
-
-
فایل
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .