🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / Android RMOS / custom AlertDialog recylerview

1-) Android RMOS - custom AlertDialog recylerview

 

private void showSortPopup() {
    LayoutInflater inflater = getLayoutInflater();
    View alertLayout = inflater.inflate(R.layout.
aciklama_base, null);

    List<AciklamaModel> aciklamaModelList =
new ArrayList<>();

    
for (int i = 0; i < 5; i++) {
        AciklamaModel model=
new AciklamaModel(i,"SOĞANSIZ "+i,false);
        aciklamaModelList.add(model);
    }
    RecyclerView RecylerView_aciklama=alertLayout.findViewById(R.id.
RecylerView_aciklama);
    
final AciklamaAdapter aciklamaAdapter = new AciklamaAdapter(aciklamaModelList, new AciklamaClick() {
        
@Override
        
public void onItemClick(AciklamaModel item, int index) {

        }
    },getContext());
    GridLayoutManager  mLayoutManager =
new GridLayoutManager(getActivity(), 1);
    RecylerView_aciklama.setLayoutManager(mLayoutManager);
    RecylerView_aciklama.setItemAnimator(
new DefaultItemAnimator());
    RecylerView_aciklama.setAdapter(aciklamaAdapter);
    aciklamaAdapter.notifyDataSetChanged();


    AlertDialog.Builder alert =
new AlertDialog.Builder(getContext());
    alert.setTitle(
seciliSiparisModel.getUrunAd());
    
// this is set the view from XML inside AlertDialog
    
alert.setView(alertLayout);
    
// disallow cancel of AlertDialog on click of back button and outside touch
    
alert.setCancelable(false);


    alert.setNegativeButton(
"İPTAL", new DialogInterface.OnClickListener() {
        
@Override
        
public void onClick(DialogInterface dialog, int which) {
            
actionMode.finish();
        }
    });
    alert.setPositiveButton(
"KAYDET", new DialogInterface.OnClickListener() {
        
@Override
        
public void onClick(DialogInterface dialog, int which) {
            
actionMode.finish();
        }
    });
    AlertDialog dialog = alert.create();
    dialog.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.
SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.show();
}

 

 

------ aciklama_base.xml ------

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
android:layout_width="match_parent"
    
android:layout_height="match_parent"
    
android:padding="16dp">
    <
ScrollView
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content">
        <
LinearLayout
            
android:layout_width="match_parent"
            
android:layout_height="wrap_content"
            
>

            <
LinearLayout
                
android:layout_width="match_parent"
                
android:layout_height="match_parent"
                
android:orientation="vertical">

                <
androidx.recyclerview.widget.RecyclerView
                    
android:id="@+id/RecylerView_aciklama"
                    
android:layout_width="match_parent"
                    
android:layout_height="250dp">

                </
androidx.recyclerview.widget.RecyclerView>

                <
com.google.android.material.textfield.TextInputLayout
                    
android:layout_width="match_parent"
                    
android:layout_height="match_parent">

                    <
EditText
                        
android:id="@+id/txtAciklamaDetay"
                        
android:layout_width="match_parent"
                        
android:layout_height="wrap_content"
                        
android:layout_weight="1"
                        
android:hint="Açıklama Giriniz"
                        
android:inputType="textMultiLine|text" />

                </
com.google.android.material.textfield.TextInputLayout>

            </
LinearLayout>

        </
LinearLayout>

    </
ScrollView>
</
RelativeLayout>

 

 

 

------ aciklama_item.xml ------

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
xmlns:tools="http://schemas.android.com/tools"
    
xmlns:app="http://schemas.android.com/apk/res-auto"
    
android:layout_width="match_parent"
    
android:layout_height="wrap_content"
    
android:orientation="horizontal"
    
android:layout_marginLeft="10dp"
    
android:layout_marginRight="10dp"
    
>
    <
androidx.cardview.widget.CardView
        
android:id="@+id/view2"
        
android:layout_width="match_parent"
        
android:layout_height="wrap_content"
        
android:layout_margin="3dp"
        
android:orientation="vertical"
        
app:cardCornerRadius="15dp">

        <
LinearLayout
            
android:id="@+id/linearAciklama"
            
android:layout_width="match_parent"
            
android:layout_height="40dp"
            
android:orientation="vertical"
            
>
            <
LinearLayout
                
android:layout_width="match_parent"
                
android:layout_height="match_parent"
                
android:gravity="center"
                
android:orientation="horizontal"
                
android:weightSum="100">
                <
TextView
                    
android:id="@+id/txtAciklamaAd"
                    
android:layout_width="0dp"
                    
android:layout_height="match_parent"
                    
android:layout_weight="90"
                    
android:gravity="center"
                    
android:paddingLeft="5dp"
                    
android:textColor="@android:color/black"
                    
android:textSize="12dp"
                    
android:textStyle="bold"
                    
tools:text="SOĞANSIZ" />
                <
ImageView
                    
android:id="@+id/imageView_aciklama"
                    
android:layout_width="24dp"
                    
android:layout_height="24dp"
                     
/>
            </
LinearLayout>
        </
LinearLayout>
    </
androidx.cardview.widget.CardView>
</
RelativeLayout>

 

------ AciklamaAdapter.java ------

 

package com.ramazan.rmosposx.Grup.Aciklama;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import com.ramazan.rmosposx.R;
import java.util.List;

public class AciklamaAdapter extends RecyclerView.Adapter<AciklamaAdapter.RecyclerAdapterIcteki> {
    
private List<AciklamaModel> modelList;
    
private AciklamaClick mListener;
    Context
context;
    
public class RecyclerAdapterIcteki extends RecyclerView.ViewHolder {
        
public TextView txtAciklamaAd;
        
public AciklamaModel AciklamaModel;
        
public LinearLayout linearAciklama;
        
public int position;
        
public ImageView imageView_aciklama;


        
public RecyclerAdapterIcteki(final View view) {
            
super(view);
            
txtAciklamaAd = view.findViewById(R.id.txtAciklamaAd);
            
linearAciklama = view.findViewById(R.id.linearAciklama);
            
imageView_aciklama = view.findViewById(R.id.imageView_aciklama);
        }
    }
    
public AciklamaAdapter(List<AciklamaModel> modelList, AciklamaClick mListener, Context context) {
        
this.mListener = mListener;
        
this.modelList = modelList;
        
this.context=context;
    }

    
@Override
    
public RecyclerAdapterIcteki onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.
from(parent.getContext())
                .inflate(R.layout.
aciklama_item, parent, false);

        
return new RecyclerAdapterIcteki(itemView);
    }
    
public int row_index = -1;
    AciklamaAdapter.RecyclerAdapterIcteki
holder;
    
public void setSec(int position) {
        
row_index = position;
        notifyDataSetChanged();
    }

    
public void imageSec(ImageView imageView) {

    }

    
@Override
    
public void onBindViewHolder(@NonNull AciklamaAdapter.RecyclerAdapterIcteki holder, final int position) {
        
this.holder = holder;
        holder.
position = position;
        
final AciklamaModel aciklamaModel = modelList.get(position);
        holder.
AciklamaModel = aciklamaModel;

        holder.
linearAciklama.setTag(aciklamaModel.getId());
        holder.
txtAciklamaAd.setText(aciklamaModel.getAciklamaAd());



        holder.
linearAciklama.setOnClickListener(new View.OnClickListener() {
            
@Override
            
public void onClick(View view) {
                
row_index = position;
                
aciklamaModel.setSecili(!aciklamaModel.isSecili());
                notifyDataSetChanged();
                
mListener.onItemClick(modelList.get(position), position);
            }
        });
        
if (aciklamaModel.isSecili()) {
            holder.
linearAciklama.setBackgroundColor(Color.BLUE);
            holder.
txtAciklamaAd.setTextColor(Color.WHITE);

            Drawable icon;
            
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                icon = VectorDrawableCompat.
create(context.getResources(), R.drawable.okey_green, context.getTheme());
            }
else {
                icon =
context.getResources().getDrawable(R.drawable.okey_green, context.getTheme());
            }
            holder.
imageView_aciklama.setImageDrawable(icon);

        }
else {
            holder.
linearAciklama.setBackgroundColor(Color.WHITE);
            holder.
txtAciklamaAd.setTextColor(Color.BLACK);
            holder.
imageView_aciklama.setImageDrawable(null);
        }
    }
    
@Override
    
public int getItemCount() {
        
return modelList.size();
    }
}

 

 2021 Ocak 18 Pazartesi
 373