i have two adaptors the Childadaptor inside Mainadapter i want to scroll to a position in the Mainadaptor then scroll to a position in the Childadaptor in android studio java i have 120000 of Childadaptor in Mainadaptor and i have 100 textview in each Childadaptor how can i make it..
my QuranMainAdapter
public class QuranMainAdapter extends RecyclerView.Adapter<QuranMainAdapter.ViewMainHolder>{
Context context;
ArrayList<QuranClass> textClasses;
private final ScaleGestureDetector scaleGestureDetector;
private float initialTextSize;
private float textSize;
SharedPreferences preferences;
SharedPreferences preferencesPos;
public QuranMainAdapter(Context context, ArrayList<QuranClass> textClasses ) {
this.context =context;
this.textClasses = textClasses;
preferences = context.getSharedPreferences("size",MODE_PRIVATE);
preferencesPos = context.getSharedPreferences("quran",MODE_PRIVATE);
textSize = preferences.getFloat("size",35.0f);
scaleGestureDetector = new ScaleGestureDetector(context, new ScaleGestureListener());
}
@NonNull
@Override
public ViewMainHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View singleRow = LayoutInflater.from(context)
.inflate(R.layout.quraan_recycler_item, parent, false);
return new ViewMainHolder(singleRow);
}
@Override
public void onBindViewHolder(@NonNull ViewMainHolder holder, int i) {
QuranClass dataList = textClasses.get(i);
String sureName = dataList.getName();
String qty = dataList.getType();
Intent intent = new Intent("custom-message");
intent.putExtra("surahName",sureName);
intent.putExtra("surahType",qty);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
holder.recyclerView.setLayoutManager(layoutManager);
QuranChildAdapter childAdapter = new QuranChildAdapter(context,dataList.getAya());
childAdapter.setTextSize(textSize);
holder.recyclerView.setAdapter(childAdapter);
int po = preferencesPos.getInt("positionChild",0);
int firstPo = preferencesPos.getInt("position",0);
if (firstPo == i){
holder.recyclerView.smoothScrollToPosition(po);
}
holder.recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
preferencesPos.edit().putInt("position",i).apply();
if (event.getPointerCount()==2){
scaleGestureDetector.onTouchEvent(event);
}
return true;
}
});
}
@Override
public int getItemCount() {
if (textClasses ==null){
return 0;
}else {
return textClasses.size();
}
}
public static class ViewMainHolder extends RecyclerView.ViewHolder{
RecyclerView recyclerView;
public ViewMainHolder(@NonNull View itemView) {
super(itemView);
recyclerView = itemView.findViewById(R.id.quran_item_rec);
}
}
public void setTextSize(float textSize) {
SharedPreferences.Editor editor = preferences.edit();
editor.putFloat("size", textSize);
editor.apply();
this.textSize =textSize;
notifyDataSetChanged();
}
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
// Calculate the scale factor from the gesture detector
float scaleFactor = detector.getScaleFactor();
// Calculate the new text size based on the initial text size and the scale factor
float newTextSize = initialTextSize * scaleFactor;
// Apply the new text size to the child adapter
setTextSize(newTextSize);
return true;
}
@Override
public boolean onScaleBegin(@NonNull ScaleGestureDetector detector) {
// Set the initial text size
initialTextSize = textSize;
return true;
}
}
}
my QuranChildAdapter that i need to scroll after QuranMainAdapter finish scrolling.
public class QuranChildAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<Verse> childItemList;
Context context;
private float textSize;
public QuranChildAdapter(Context context, List<Verse> childItemList) {
this.childItemList = childItemList;
this.context =context;
this.textSize = 35.0f; // Default text size
}
@NotNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
switch (i) {
case 0:
return new Header_guran(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.quraan_header_item, viewGroup, false));
case 1:
return new base_quran(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.quraan_basm_item, viewGroup, false));
case 2:
View itemView =LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.quraan_surha_item,
viewGroup, false);
return new main_quran(itemView);
default:
return new footer_quran(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.quraan_footer_item, viewGroup, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder myHolder, int ii) {
Verse dataList = childItemList.get(ii);
switch (myHolder.getItemViewType()) {
case 0:
((Header_guran) myHolder).header_lie.setVisibility(View.VISIBLE);
((Header_guran) myHolder).header.setText(dataList.getSurahName());
break;
case 1:
((base_quran) myHolder).basm.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
((base_quran) myHolder).basm.setVisibility(View.VISIBLE);
break;
case 2:
SpannableStringBuilder pages;
pages = new SpannableStringBuilder();
String end = "<font color='#63824E'>" + "\u06DD" + dataList.getAyahNumberInSurah() + "</font>";
String ayahSpannable = dataList.getSurahAyahText();
Spanned endSpannable = HtmlCompat.fromHtml(end, 0);
Typeface ayahFont = Typeface.createFromAsset(context.getAssets(), "font/amiri_quran.ttf");
pages.append(ayahSpannable)
.append(endSpannable);
((main_quran) myHolder).textView.setTypeface(ayahFont);
((main_quran) myHolder).textView.setText(pages);
((main_quran) myHolder).textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
int i = ii;
((main_quran) myHolder).textView.setOnTouchListener(new View.OnTouchListener() {
SharedPreferences preferencesChild;
@Override
public boolean onTouch(View view, MotionEvent event) {
preferencesChild =context.getSharedPreferences("quran",MODE_PRIVATE);
preferencesChild.edit().putInt("positionChild",i).apply();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
((main_quran) myHolder).textView.setShadowLayer(1, 0, 0, Color.BLACK);
break;
case MotionEvent.ACTION_UP:
((main_quran) myHolder).textView.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
break;
case MotionEvent.ACTION_CANCEL:
((main_quran) myHolder).textView.setShadowLayer(0, 0, 0, Color.TRANSPARENT);
break;
}
return false;
}
});
break;
default:
((footer_quran) myHolder).footer.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);;
((footer_quran) myHolder).footer.setText(String.format("-﴿ %s ﴾-", dataList.getPage()));
break;
}
}
@Override
public int getItemCount() {
if (childItemList ==null){
return 0;
}else {
return childItemList.size();
}
}
@Override
public int getItemViewType(int position) {
Verse dataList = childItemList.get(position);
String type = dataList.getTypeView();
if ("header".equals(type)) {
return 0;
} else if ("bismillah".equals(type)) {
return 1;
} else if ("verse".equals(type)) {
return 2;
} else {
return 3;
}
}
public class Header_guran extends RecyclerView.ViewHolder {
TextView header;
LinearLayout header_lie;
public Header_guran(@NonNull View itemView) {
super(itemView);
header = itemView.findViewById(R.id.sure_name_header);
header_lie = itemView.findViewById(R.id.card_header_quran);
}
}
public class base_quran extends RecyclerView.ViewHolder{
TextView basm;
public base_quran(@NonNull View itemView) {
super(itemView);
basm = itemView.findViewById(R.id.basm_name_header);
}
}
public class main_quran extends RecyclerView.ViewHolder{
QuranTextView textView;
public main_quran(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.text_quran);
}
}
public class footer_quran extends RecyclerView.ViewHolder{
TextView footer;
public footer_quran(@NonNull View itemView) {
super(itemView);
footer = itemView.findViewById(R.id.page_footer);
}
}
public void setTextSize(float textSize) {
this.textSize = textSize;
notifyDataSetChanged();
}
}
my activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quraan);
juse = findViewById(R.id.jouse);
suraName = findViewById(R.id.sure_name);
preferencesAct = getSharedPreferences("quran",MODE_PRIVATE);
int po = preferencesAct.getInt("position",0);
recyclerView =findViewById(R.id.quran_rec);
database = new QuraanDatabase(this);
objDbModelClassArrayList =new ArrayList<>();
objDbModelClassArrayList = database.getAllPages();
objDbAdapter = new QuranMainAdapter(this,objDbModelClassArrayList);
mLayoutManager = new AdjustLinearLayoutManager(this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(objDbAdapter );
mLayoutManager.setScrollType(mScrollType);
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
mLayoutManager.setMillisecondsPerInch(10f);
mLayoutManager.smoothScrollToPosition(recyclerView,null,po);
LocalBroadcastManager.getInstance(this).
registerReceiver(mMessageReceiver, new IntentFilter("custom-message"));
suraName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SurahQuranMain customerDialog = new SurahQuranMain();
customerDialog.show(getSupportFragmentManager(), "Surah Quran Main");
}
});
}
i have two adaptors the Childadaptor inside Mainadapter i want to scroll to a position in the Mainadaptor then scroll to a position in the Childadaptor in android studio java i have 120000 of Childadaptor in Mainadaptor and i have 100 textview in each Childadaptor i want exmple for adaptors also