How to add items to recyclerview programmatically? [duplicate] - android

I have a button(save contact) to save contacts ,the button when pressed get name and email from edit text and should dynamically add 1 list item in recycle view
The save button is in fragment
This is the name which i am extracting
company_name=(EditText)view.findViewById(R.id.edittext_companyname_createMeeting);
When i click on lead it should add in the existing recycleview
leads.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
newValueAdapter.newAddeddata(company_name.getText().toString());*/
}
});
The recycle view already have a arraylist,how do i add new value to the arraylist and again call oncreate
I tried to extract company name and send it to the adapter of that recycler view but it dint work
Adapter of RecyclerView
public class NewleadsAdapter extends RecyclerView.Adapter<NewleadsAdapter.MyViewHolder> {
Context context;
LayoutInflater inflater;
int positionbundle;
ArrayList<NewleadsPOJO> datalist;
public NewleadsAdapter(Context context, ArrayList<NewleadsPOJO> datalist,int positionbundle){
this.context=context;
this.datalist=datalist;
this.positionbundle=positionbundle;
}
/* public NewleadsAdapter(){}*/
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view=LayoutInflater.from(context).inflate(R.layout.custom_new_leads,parent,false);
MyViewHolder myViewHolder=new MyViewHolder(view);
return myViewHolder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.leads_company.setText(datalist.get(position).getLeads_company());
holder.leads_date.setText(datalist.get(position).getLeads_date());
holder.leads_time.setText(datalist.get(position).getLeads_time());
if (positionbundle == 1){
/* holder.icon1.setVisibility(View.GONE);*/
holder.icon1.setImageResource(R.drawable.taskcompletednewblue);
}else{}
Log.e("Create_meetingdate_ArrayList:", datalist.get(0).getLeads_company()); /* Arrays.deepToString(data.toArray())*/
System.out.println(datalist.get(0).getLeads_company());
}
#Override
public int getItemCount() {
return datalist.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView leads_company,leads_date,leads_time;
ImageView icon1;
public MyViewHolder(View itemView) {
super(itemView);
leads_company=(TextView)itemView.findViewById(R.id.leads_company);
leads_date=(TextView)itemView.findViewById(R.id.leads_date);
leads_time=(TextView)itemView.findViewById(R.id.leads_time);
icon1=(ImageView)itemView.findViewById(R.id.leads_info);
}
}
/*public void newAddeddata(String company_name){
NewleadsPOJO newValue=new NewleadsPOJO();
newValue.setLeads_company(company_name);
datalist.add(datalist.size(),newValue);
}*/
}
Createmeetingfrag.java
public class CreateMeetingFrag extends Fragment {
TextView leads,cold,warm,hot,closed;
EditText company_name,email,date,time;
public CreateMeetingFrag() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_create_meeting, container, false);
company_name=(EditText)view.findViewById(R.id.edittext_companyname_createMeeting);
leads=(TextView)view.findViewById(R.id.meeting_leads);
cold=(TextView)view.findViewById(R.id.meeting_cold);
warm=(TextView)view.findViewById(R.id.meeting_warm);
hot=(TextView)view.findViewById(R.id.meeting_hot);
closed=(TextView)view.findViewById(R.id.meeting_closed);
leads.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//getSavedValues();
/* NewleadsAdapter newValueAdapter=new NewleadsAdapter();
newValueAdapter.newAddeddata(company_name.getText().toString());*/
NewleadsAdapter newValue=new NewleadsAdapter();
newValue.newAddeddata(company_name.getText().toString());
setDefaultValues();
leads.setBackgroundColor(getResources().getColor(R.color.blue));
Toast.makeText(getActivity(),"leads clicked and saved",Toast.LENGTH_SHORT).show();
leads.setTextColor(getResources().getColor(R.color.white));
}
});
cold.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDefaultValues();
cold.setBackgroundColor(getResources().getColor(R.color.blue));
Toast.makeText(getActivity(),"leads clicked",Toast.LENGTH_SHORT).show();
cold.setTextColor(getResources().getColor(R.color.white));
}
});
warm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDefaultValues();
warm.setBackgroundColor(getResources().getColor(R.color.blue));
Toast.makeText(getActivity(),"leads clicked",Toast.LENGTH_SHORT).show();
warm.setTextColor(getResources().getColor(R.color.white));
}
});
hot.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDefaultValues();
hot.setBackgroundColor(getResources().getColor(R.color.blue));
Toast.makeText(getActivity(),"leads clicked",Toast.LENGTH_SHORT).show();
hot.setTextColor(getResources().getColor(R.color.white));
}
});
closed.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDefaultValues();
closed.setBackgroundColor(getResources().getColor(R.color.blue));
Toast.makeText(getActivity(),"leads clicked",Toast.LENGTH_SHORT).show();
closed.setTextColor(getResources().getColor(R.color.white));
}
});
return view;
}
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setDefaultValues(){
leads.setBackgroundColor(getResources().getColor(R.color.white));
cold.setBackgroundColor(getResources().getColor(R.color.white));
warm.setBackgroundColor(getResources().getColor(R.color.white));
hot.setBackgroundColor(getResources().getColor(R.color.white));
closed.setBackgroundColor(getResources().getColor(R.color.white));
closed.setTextColor(getResources().getColor(R.color.black_semi_transparent));
hot.setTextColor(getResources().getColor(R.color.black_semi_transparent));
warm.setTextColor(getResources().getColor(R.color.black_semi_transparent));
cold.setTextColor(getResources().getColor(R.color.black_semi_transparent));
leads.setTextColor(getResources().getColor(R.color.black_semi_transparent));
leads.setBackground(getResources().getDrawable(R.drawable.bordder_button));
closed.setBackground(getResources().getDrawable(R.drawable.bordder_button));
hot.setBackground(getResources().getDrawable(R.drawable.bordder_button));
warm.setBackground(getResources().getDrawable(R.drawable.bordder_button));
cold.setBackground(getResources().getDrawable(R.drawable.bordder_button));
}
}

Add this method to your adapter and call on button click.
public void newAddeddata(String company_name){
NewleadsPOJO newValue=new NewleadsPOJO();
newValue.setLeads_company(company_name);
datalist.add(newValue);
notifyDataSetChanged();
}
Add following method to NewLeadFrag
public NewleadsAdapter getAdapter(){
return adapter;
}
now in Createmeetingfrag
leads.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
NewLeadFrag fragment = getFragmentManager().findFragmentByTag("NewLeadFrag_TAG"); //set tag of fragment when you add with fragment manager. and if you are using support library use getSupportFragmentManager()
if(fragment!= null){
fragment.getAdapter().newAddeddata(company_name.getText().toString());
}
}
});

You don't need to go through the entire life cycle of your Activity or Fragment just because you've made changes to the list. Instead try adding the item in the list you currently have associated with the Adapter. And then call adapter.notifyDataSetChange(). This should automatically add the new Item to the RecyclerView.

How to add items and delete items in recycler view using floating button in java(android).
Add this dependency.
implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.google.code.gson:gson:2.8.6'
MainActivity.java
fab = (FloatingActionButton) view.findViewById(R.id.fab_id);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater li = LayoutInflater.from(getContext());
View v = li.inflate(R.layout.layout_dialog, null);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext());
alertDialog.setTitle("Add Data");
EditText title = v.findViewById(R.id.edittext_title);
EditText description = v.findViewById(R.id.editview_description);
alertDialog.setView(v);
alertDialog.setPositiveButton("Add",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Gson gson = new Gson();
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", title.getText().toString());
jsonObject.put("description", description.getText().toString());
item item = gson.fromJson(String.valueOf(jsonObject), item.class);
items.add(item);
Adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
alertDialog.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog
dialog.cancel();
}
});
alertDialog.show();
}
});
layout_dialog.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:padding="60dp">
<EditText
android:id="#+id/edittext_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/enter_title"
app:layout_constraintBottom_toTopOf="#+id/editview_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints"
android:inputType="text"
android:autofillHints="" />
<EditText
android:id="#+id/editview_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:hint="#string/enter_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edittext_title"
tools:ignore="MissingConstraints"
android:autofillHints=""
android:inputType="text" />
Adapter.java
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {
List<item> mdata;
public Adapter(List<item> mdata) {
this.mdata = mdata;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_item, parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.tilte.setText(mdata.get(position).getTitle());
holder.Description.setText(mdata.get(position).getDescription());
holder.imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mdata.remove(position);
notifyDataSetChanged();
}
});
}
#Override
public int getItemCount() {
return mdata.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
TextView tilte,Description;
ImageView imageView;
public ViewHolder(#NonNull View itemView) {
super(itemView);
tilte=itemView.findViewById(R.id.title);
Description=itemView.findViewById(R.id.description);
imageView = itemView.findViewById(R.id.remove_image);
}
}
}
layout_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="55dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:contentDescription="#string/mark"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/circle_img" />
<View
android:id="#+id/view"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#800080"
app:layout_constraintBottom_toBottomOf="#+id/description"
app:layout_constraintEnd_toEndOf="#id/imageView"
app:layout_constraintStart_toStartOf="#id/imageView"
app:layout_constraintTop_toBottomOf="#id/imageView" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="16dp"
android:textStyle="bold"
android:textSize="16sp"
android:inputType="text"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:lineSpacingExtra="1sp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/title" />
<ImageView
android:id="#+id/remove_image"
android:layout_width="20dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:contentDescription="#string/remove_item"
app:layout_constraintEnd_toStartOf="#+id/title"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#android:drawable/ic_menu_close_clear_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>
item.java
public class item {
private String title;
private String description;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public item(String title, String description) {
this.title = title;
this.description = description;
}
}

layout
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvContactNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
tools:itemCount="2"
tools:listitem="#layout/row_add_contact_number" />
java
private ArrayList<ContactNumberModel> arrayList;
private ContactNumberAdapter adapter;
onCreate
arrayList = new ArrayList<>();
arrayList.add(new ContactNumberModel());
adapter = new ContactNumberAdapter(context);
binding.rvContactNumber.setLayoutManager(new LinearLayoutManager(context));
binding.rvContactNumber.setHasFixedSize(true);
binding.rvContactNumber.setAdapter(adapter);
ContactNumberModel.java
public class ContactNumberModel {
private String contactNo;
public String getContactNo() {
return contactNo;
}
public void setContactNo(String contactNo) {
this.contactNo = contactNo;
}
}
ContactNumberAdapter.java
public class ContactNumberAdapter extends RecyclerView.Adapter<ContactNumberAdapter.ViewHolder> {
private Context context;
private ArrayList<ContactNumberModel> arrayList;
public ContactNumberAdapter(Context context) {
this.context = context;
this.arrayList = new ArrayList<>();
this.arrayList.add(new ContactNumberModel());
}
#NonNull
#Override
public ContactNumberAdapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
RowAddContactNumberBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.row_add_contact_number, parent, false);
return new ViewHolder(binding);
}
#Override
public void onBindViewHolder(#NonNull final ContactNumberAdapter.ViewHolder holder, int position) {
ContactNumberModel model = arrayList.get(position);
//holder.bind(model);
holder.binding.etContactNumber.setText("");
holder.binding.etContactNumber.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
arrayList.get(holder.getAdapterPosition()).setContactNo(editable.toString());
}
});
if (arrayList.size() - 1 == holder.getAdapterPosition()) {
holder.binding.tvAddMore.setVisibility(View.VISIBLE);
holder.binding.ivRemove.setVisibility(View.GONE);
} else {
holder.binding.tvAddMore.setVisibility(View.GONE);
holder.binding.ivRemove.setVisibility(View.VISIBLE);
}
holder.binding.ivRemove.setOnClickListener(null);
holder.binding.tvAddMore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
addNewRow();
}
});
}
public void addNewRow() {
this.arrayList.add(new ContactNumberModel());
notifyDataSetChanged();
}
#Override
public int getItemCount() {
return arrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
RowAddContactNumberBinding binding;
public ViewHolder(RowAddContactNumberBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
public void bind(ContactNumberModel model) {
binding.setContact(model);
binding.executePendingBindings();
}
}
}
row_add_contact_number.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="contact"
type="com.appname.model.ContactNumberModel" />
</data>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_10sdp"
android:orientation="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_15sdp"
android:layout_marginRight="#dimen/_15sdp"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:theme="#style/TextInputLayoutHint">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/etContactNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:focusableInTouchMode="true"
android:hint="Enter Contact Number"
android:inputType="number"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvAddMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_3sdp"
android:layout_marginLeft="#dimen/_3sdp"
android:fontFamily="#font/font_barlow"
android:gravity="center"
android:text="#string/add_more"
android:textColor="#color/colorOrange"
android:textSize="#dimen/_12ssp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/ivRemove"
android:layout_width="#dimen/_15sdp"
android:layout_height="#dimen/_15sdp"
android:layout_marginLeft="#dimen/_5sdp"
android:adjustViewBounds="true"
android:src="#drawable/ic_logo"
android:visibility="gone" />
</androidx.appcompat.widget.LinearLayoutCompat>
<View style="#style/Divider" />
</androidx.appcompat.widget.LinearLayoutCompat>
</layout>

Related

Call contacts from a list in Android Studio

I have an Android application where I used Linear Layout that shows a list of contacts. Now what I want is that when selecting the contacts, call the indicated number.
For now, all it do is show the contacts, but when I click on call, it does not take any action. I do not know how to make to mark
I tried with setOnClickListener().But Unsuccessful
My code:
public class ContactsAdapter extends RecyclerView.Adapter<ContactsAdapter.ContactViewHolder>{
Dialog myDialog;
private List<ContactModel> contactModelList;
private Context mContext;
public ContactsAdapter(List<ContactModel> contactModelList, Context mContext){
this.contactModelList = contactModelList;
this.mContext = mContext;
}
#Override
public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.single_contact_view, null);
ContactViewHolder contactViewHolder = new ContactViewHolder(view);
return contactViewHolder;
}
#Override
public void onBindViewHolder(ContactViewHolder holder, int position) {
final ContactModel contactModel = contactModelList.get(position);
holder.tvContactName.setText(contactModel.getContactName());
holder.tvPhoneNumber.setText(contactModel.getContactNumber());
holder.contactsRowLV.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View view) {
Toast.makeText(mContext,""+ contactModel.getContactNumber(),Toast.LENGTH_SHORT).show();
}
});
}
#Override
public int getItemCount() {
return contactModelList.size();
}
public static class ContactViewHolder extends RecyclerView.ViewHolder{
ImageView ivContactImage;
TextView tvContactName;
TextView tvPhoneNumber;
LinearLayout contactsRowLV;
public ContactViewHolder(View itemView) {
super(itemView);
ivContactImage = (ImageView) itemView.findViewById(R.id.ivContactImage);
tvContactName = (TextView) itemView.findViewById(R.id.tvContactName);
tvPhoneNumber = (TextView) itemView.findViewById(R.id.tvPhoneNumber);
contactsRowLV = itemView.findViewById(R.id.contactsRowLV);
}
}
}
Here I show my XML of how I have. Help me please
<LinearLayout
android:id="#+id/contactsRowLV"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivContactImage"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_gravity="center"
android:src="#drawable/ic_person"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<TextView
android:id="#+id/tvContactName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textSize="30dp"
android:textStyle="bold"
android:textColor="#android:color/primary_text_light"
android:text="Name"/>
<TextView
android:id="#+id/tvPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textSize="25dp"
android:textColor="#android:color/primary_text_light"
android:text="Phone"/>
</LinearLayout>
</LinearLayout>
You just need to add following code in setOnClickListener(). This code is used to call particular number.
#Override
public void onBindViewHolder(ContactViewHolder holder, int position) {
final ContactModel contactModel = contactModelList.get(position);
holder.tvContactName.setText(contactModel.getContactName());
holder.tvPhoneNumber.setText(contactModel.getContactNumber());
holder.contactsRowLV.setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View view) {
Toast.makeText(mContext,""+ contactModel.getContactNumber(),Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" +contactModel.getContactNumber()));
mContext.startActivity(intent);
}
});
}

Everything shows inside the dialog except the listview

I'm trying to have an edittext with a list view to choose contacts from a custom listview here is the code but everything appears except the listview:
InstantDialogBox:
public class InstantTextBoxDialog extends DialogFragment {
private EditText message;
private Button sendToAll;
private Button sendToLimited;
private ListView listContacts;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
LayoutInflater inflater=getActivity().getLayoutInflater();
View view=inflater.inflate(R.layout.intant_message,null,false);
message=(EditText)view.findViewById(R.id.instant_message);
sendToAll=(Button) view.findViewById(R.id.btn_sent_to_all);
listContacts=(ListView)view.findViewById(R.id.list_checkable);
ChackableListAdapter adapter=new ChackableListAdapter(getActivity(),R.layout.list_chackable_item,new ArrayList<Contact>());
sendToAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!TextUtils.isEmpty(message.getText())){
ChatService.bind.getService().sendMessageToAll(message.getText().toString());
message.setText("");
dismiss();
}
}
});
sendToLimited=(Button) view.findViewById(R.id.btn_send_to_limited);
sendToLimited.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!TextUtils.isEmpty(message.getText())){
}
}
});
listContacts.setAdapter(adapter);
builder.setView(view);
return builder.create();
}
CheckableListAdapter:
public class ChackableListAdapter extends ArrayAdapter<Contact> {
private ArrayList<Contact> contacts;
private int resource;
private Context context;
private ArrayList<Contact> choosen;
public ChackableListAdapter(#NonNull Context context, int resource,ArrayList<Contact> arrayList) {
super(context, resource,arrayList);
this.context=context;
this.resource=resource;
this.contacts=arrayList;
contacts= DatabaseHandler.getDataBaseHandler(context).getAllRegisteredContacts();
choosen=new ArrayList<>();
}
#Nullable
#Override
public Contact getItem(int position) {
return contacts.get(position);
}
#NonNull
#Override
public View getView(final int position, #Nullable View view, #NonNull ViewGroup parent) {
Holder holder=null;
if (view == null || view.getTag() == null) {
holder=new Holder();
view= LayoutInflater.from(context).inflate(resource,null);
holder.phone=(TextView)view.findViewById(R.id.text_number);
holder.name=(CheckBox)view.findViewById(R.id.checkbox_number);
view.setTag(holder);
}
else {
holder = (Holder) view.getTag();
}
holder.phone.setText(getItem(position).phone_number);
holder.name.setText(getItem(position).name);
holder.name.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
choosen.add(getItem(position));
}else {
int i=0;
for (Contact contact:choosen){
if(contact.phone_number.equalsIgnoreCase(getItem(position).phone_number)){
choosen.remove(i);
notifyDataSetChanged();
}
i++;
}
}
}
});
Log.wtf("generating rows"," yes");
return view;
}
private class Holder{
public CheckBox name;
public TextView phone;
}
public ArrayList<Contact> getChoosenContacts(){
return choosen;
}
}
intant_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:id="#+id/instant_message"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="5"
android:gravity="top"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/btn_send_to_limited"
android:text="send to limited"
android:layout_width="95dp"
android:textSize="10sp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
/>
<Button
android:id="#+id/btn_sent_to_all"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:text="send to all"
android:textSize="10sp"
android:layout_below="#+id/btn_send_to_limited"
android:layout_marginTop="5dp"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools">
<ListView
android:id="#+id/list_checkable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/list_chackable_item">
</ListView>
</LinearLayout>
list_chacakble_item:
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
android:id="#+id/checkbox_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abdallah"
android:textStyle="bold"/>
<TextView
android:id="#+id/text_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7656156165156651"
android:layout_marginLeft="30dp"/>
The dialog box is trigered from an adapter of a listview and that's the adapter's code:
holder.replay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
InstantTextBoxDialog exampleDialog=new InstantTextBoxDialog();
exampleDialog.show(((Activity) activity).getFragmentManager(),"sadsdadsaadassd");
}
});
But till now nothing shows except the buttons and no listview

How to box each word after user presses space/comma in android studio?

I'm currently trying to make an android application and I've run into a problem. How would you allow for user to type a word and once they press space/comma, it boxes the word, preferably with an exit option.
https://i.stack.imgur.com/BwpZ9.png
https://i.stack.imgur.com/zqOLo.png
Anything along the lines of these pictures would be perfect.
What you are wanting is called chips in Android, it's one of the native designs you can read about it's specification here.
Here are a few example to get you started, last time I checked there was no proper documentation or support for this feature so I ended up using one the libraries that has built it, you can do something yourself by implementing a custom view as explained here
Here is how I would implement it. This is a working example. When the user hits space it adds and item. When you click an item it will remove it.
Here is a gif of it in action.
https://giphy.com/gifs/l4EpayEaAuGV58tgY
add to gradle:
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.xiaofeng.android:flowlayoutmanager:1.2.3.2'
classes
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler);
recyclerView.setLayoutManager(new FlowLayoutManager());
recyclerView.setAdapter(new CustomRecyclerAdapter());
}
}
public class CustomRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int HOLDER_ERROR = 0;
private static final int HOLDER_BOX = 1;
private static final int HOLDER_EDIT = 2;
private List<Object> objectList = new ArrayList<>();
public CustomRecyclerAdapter() {
objectList.add(0);
}
public void addItem(String item) {
objectList.add(getItemCount() - 1, item);
notifyItemInserted(getItemCount() - 1);
}
public void removeItem(int position) {
objectList.remove(position);
notifyItemRemoved(position);
}
#Override
public int getItemCount() {
return objectList.size();
}
#Override
public int getItemViewType(int position) {
if (objectList.get(position) instanceof String) {
return HOLDER_BOX;
} else if (objectList.get(position) instanceof Integer) {
return HOLDER_EDIT;
} else {
return HOLDER_ERROR;
}
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case HOLDER_ERROR:
return null;
case HOLDER_BOX:
return new ViewHolderBox(LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_box, parent, false));
case HOLDER_EDIT:
return new ViewHolderEdit(LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_edit_text, parent, false));
default:
return null;
}
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolderBox) {
ViewHolderBox mHolder = (ViewHolderBox) holder;
mHolder.bindItems();
} else if (holder instanceof ViewHolderEdit) {
ViewHolderEdit mHolder = (ViewHolderEdit) holder;
mHolder.bindItems();
}
holder.itemView.setTag(this);
}
private class ViewHolderEdit extends RecyclerView.ViewHolder implements TextWatcher {
private EditText edit;
private ViewHolderEdit(View itemView) {
super(itemView);
edit = itemView.findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager) itemView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(edit.getWindowToken(), 0);
}
private void bindItems() {
edit.addTextChangedListener(this);
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String editString = edit.getText().toString();
Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(editString);
if (matcher.find()) {
if (!editString.trim().equalsIgnoreCase("")) {
addItem(editString.trim());
edit.setText("");
edit.requestFocus();
}
}
}
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
}
}
private class ViewHolderBox extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView text;
private ViewHolderBox(View itemView) {
super(itemView);
text = itemView.findViewById(R.id.text);
text.setOnClickListener(this);
}
private void bindItems() {
String item = (String) objectList.get(getAdapterPosition());
text.setText(item);
}
#Override
public void onClick(View view) {
removeItem(getAdapterPosition());
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="resume.eugene.com.testing.MainActivity" />
recycler_box.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="34dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="2dp"
android:background="#90CAF9"
android:clickable="true"
android:gravity="center"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="Testing" />
</LinearLayout>
recycler_edit_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edit"
android:layout_width="wrap_content"
android:layout_height="34dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="2dp"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:hint="Add Item"
android:minWidth="50dp"
android:textSize="15sp" />
</LinearLayout>

Android Recycler view with onClickListener not working

I'm trying to set an onClickListener on one of my image on my recyclerview but the click doesn't work.
It looks like it doesn't seems to see there is a onClickListener, because when I set a "point" for the debugger on my listener it doesn't go to the point.
What I have done wrong ?
public class Item_List_Adapter extends RecyclerView.Adapter<Item_List_Adapter.MyViewHolder> {
// declare array
private String[] mDataset;
private Context mContext;
public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
public TextView itemName;
public ImageView mAddBtn;
public MyViewHolder(View v){
super(v);
itemName = (TextView) v.findViewById(R.id.item_name);
mAddBtn = (ImageView) v.findViewById(R.id.action_add);
}
#Override
public void onClick(View v) {
System.out.println("TEST: ");
switch (v.getId()) {
case R.id.action_add:
System.out.println("TEST2: ");
break;
default:
break;
}
}
}
// constructor
public Item_List_Adapter(Context context, String[] myDataset) {
mDataset = myDataset;
mContext = context;
}
#Override
public int getItemCount() {
return mDataset.length;
}
#Override
public Item_List_Adapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false);
MyViewHolder nv = new MyViewHolder(v);
return nv;
}
#Override
public void onBindViewHolder(Item_List_Adapter.MyViewHolder holder, final int position) {
holder.itemName.setText(mDataset[position]);
holder.mAddBtn.setOnClickListener(holder);
}
}
and my XML file the one inflate in the recycler view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<LinearLayout
android:id="#+id/list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp">
<ImageView
android:id="#+id/action_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_check"
android:alpha="0.3"
/>
<TextView
android:id="#+id/item_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".2"
android:hint="Wine"
android:alpha="0.3"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingLeft="5dp"/>
<ImageView
android:id="#+id/action_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_remove_green"
android:onClick="item_remove"
/>
<ImageView
android:id="#+id/action_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_add_blue"
/>
<ImageView
android:id="#+id/action_chart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_chart"
android:scaleType="centerInside"
android:onClick="chart_detail"
/>
</LinearLayout>
</LinearLayout>
Thanks in advance
you should use Log to output to the console
Log.d("TAG","TEST: );
for experimentation sake try this out in your ViewHolder constructor
mAddBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.d("TAG","TEST: );
}
});
If it doesn't work then something is blocking the click, this could be simply setting clickable="true" in the xml, or figuring out what is on front of the view
The following is how I used in my Adapter. Hope this help:
public class EventArrayAdapter extends RecyclerView.Adapter<ViewHolder> {
private OnItemClickListener onItemClickListener;
public OnItemClickListener getOnItemClickListener() {
return onItemClickListener;
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
//Add your viewHolder.button.setOnClickListener here as normal
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int arg1) {
// TODO Auto-generated method stub
View v = LayoutInflater.from(context).inflate(
R.layout.layout_item_event, parent, false);
final EventViewHolder holder = new EventViewHolder(v);
v.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
onItemClickListener.onItemClick(v, holder.getAdapterPosition());
}
});
return holder;
}
}
update your constructor like this and try. It will work.
public MyViewHolder(View v){
super(v);
itemName = (TextView) v.findViewById(R.id.item_name);
mAddBtn = (ImageView) v.findViewById(R.id.action_add);
mAddBtn.setOnClickListener(this);
}
Basically assign onClick listener to your Imageview

How to Add and Remove Recycler listview items inside element

This is my Adapter class
public class NewFeePlanAdapter extends RecyclerView.Adapter<NewFeePlanAdapter.MyViewHolder> {
Context context;
ArrayList<FeeTypeModel> feeTypeModelArrayList;
public NewFeePlanAdapter(Context context, ArrayList<FeeTypeModel> feeTypeModelArrayList){
this.context = context;
this.feeTypeModelArrayList = feeTypeModelArrayList;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.new_fee_list_row, parent,false);
MyViewHolder myViewHolder = new MyViewHolder(itemView,new MyCustomEditTextListener());
return myViewHolder;
}
FeeTypeModel feeTypeModel;
#Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
feeTypeModel = feeTypeModelArrayList.get(position);
holder.fee_type_name_tv.setText(feeTypeModel.getFeeType().toString());
if (feeTypeModel.getLinearLayout()!=null) {
holder.new_plan_main_ll.addView(feeTypeModel.getLinearLayout());
}
holder.myCustomEditTextListener.updatePosition(position);
holder.fee_amount_et.setText( feeTypeModelArrayList.get(position).getAmount());
holder.fee_type_cb.setOnCheckedChangeListener(null);
holder.fee_type_cb.setChecked(feeTypeModel.isSelectPlan());
holder.fee_type_cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
feeTypeModelArrayList.get(position).setSelectPlan(isChecked);
}
});
holder.add_installments_iv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (holder.fee_amount_et.getText().length() == 0){
Toast.makeText(context,"Please Enter Amount",Toast.LENGTH_LONG).show();
}else {
showDialogForNumberOfInstallments(v,position,Long.parseLong(holder.fee_amount_et.getText().toString()));
}
}
});
}
#Override
public int getItemCount() {
return feeTypeModelArrayList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView fee_type_name_tv;
EditText fee_amount_et;
ImageView add_installments_iv;
CheckBox fee_type_cb;
public MyCustomEditTextListener myCustomEditTextListener;
LinearLayout new_plan_main_ll;
public MyViewHolder(View view, MyCustomEditTextListener myCustomEditTextListener) {
super(view);
new_plan_main_ll = (LinearLayout)view.findViewById(R.id.new_plan_main_ll);
fee_type_cb = (CheckBox) view.findViewById(R.id.fee_type_cb);
fee_type_name_tv = (TextView) view.findViewById(R.id.fee_type_name_tv);
fee_amount_et = (EditText) view.findViewById(R.id.fee_amount_et);
add_installments_iv = (ImageView)view.findViewById(R.id.add_installments_iv);
this.myCustomEditTextListener = myCustomEditTextListener;
this.fee_amount_et.addTextChangedListener(myCustomEditTextListener);
}
}
private class MyCustomEditTextListener implements TextWatcher {
private int position;
public void updatePosition(int position) {
this.position = position;
}
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// no op
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
feeTypeModelArrayList.get(position).setAmount( charSequence.toString());
}
#Override
public void afterTextChanged(Editable editable) {
// no op
}
}
AutoCompleteTextView new_fee_plan_name_act;
EditText numberOfInstallments_et;
int selectedPosition;
private void showDialogForNumberOfInstallments(View v,int position, final long amount){
selectedPosition = position;
// Create custom dialog object
final Dialog dialog = new Dialog(context);
// Include dialog.xml file
dialog.setContentView(R.layout.new_plan_name_dialog);
dialog.setTitle("Installments");
new_fee_plan_name_act = (AutoCompleteTextView) dialog.findViewById(R.id.new_fee_plan_name_act);
new_fee_plan_name_act.setVisibility(View.GONE);
numberOfInstallments_et = (EditText)dialog.findViewById(R.id.numberOfInstallments_et);
numberOfInstallments_et.setVisibility(View.VISIBLE);
new_fee_plan_name_act.setHint("Enter Number Of Installments");
dialog.setCancelable(false);
dialog.show();
Button feePlan_cancel_bt = (Button) dialog.findViewById(R.id.feePlan_cancel_bt);
// if decline button is clicked, close the custom dialog
feePlan_cancel_bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button FeePlan_create_bt = (Button) dialog.findViewById(R.id.FeePlan_create_bt);
FeePlan_create_bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (numberOfInstallments_et.getText().toString().length()==0){
Toast.makeText(context,"Please Enter New number 0f Installments",Toast.LENGTH_LONG).show();
}else {
FeeTypeModel feeTypeModel11 = feeTypeModelArrayList.get(selectedPosition);
if (feeTypeModel11.getLinearLayout()!=null) {
feeTypeModel11.getLinearLayout().removeView(v);
}
LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new LinearLayout.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
layout.setOrientation(LinearLayout.VERTICAL);
// Toast.makeText(context,"Entered Installments "+numberOfInstallments_et.getText().toString(),Toast.LENGTH_LONG).show();
int WrapWidth = LinearLayout.LayoutParams.WRAP_CONTENT;
int WrapHeight = LinearLayout.LayoutParams.WRAP_CONTENT;
int length = Integer.parseInt(numberOfInstallments_et.getText().toString());
long instAmount = amount/length;
for (int i=0;i<length;i++){
TextView t = new TextView(context);
t.setText("Installment"+i+" "+instAmount);
layout.addView(t,WrapWidth,WrapHeight);
}
feeTypeModel11.setLinearLayout(layout);
dialog.dismiss();
notifyDataSetChanged();
}
}
});
}
}
this is my new_fee_list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:elevation="6dp"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/new_plan_main_ll"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/fee_type_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/fee_type_name_tv"
android:text="fsdfdsf"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_toLeftOf="#+id/add_installments_iv"
android:layout_height="wrap_content">
<EditText
android:id="#+id/fee_amount_et"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:maxLines="1"
android:hint="Enter Amount"
android:inputType="number"
android:singleLine="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="#+id/add_installments_iv"
android:layout_width="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#android:drawable/ic_input_add"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
//This is my main Activity class
public class NewFeePlanActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_fee_plan);
RecyclerView fee_plans_rv = (RecyclerView)findViewById(R.id.fee_plans_rv);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
fee_plans_rv.setLayoutManager(mLayoutManager);
NewFeePlanAdapter newFeePlanAdapter = new NewFeePlanAdapter(NewFeePlanActivity.this, feeTypeModelArrayList);
fee_plans_rv.setAdapter(newFeePlanAdapter);
}}
I am using above code,but my problem is adding specific position on list
** As showed above image how i need to dynamically add and remove the views each item positionin recycler view,can any one guide me with code,
your response will be appreciated..... **

Categories

Resources