How its possible when user press #button then it will print # on focused EditText of RecyclerView. My code and output is below. Please help me....
I've done everything, but got stuck in here. Can I get any suggestion or link with some more info on how to implement this?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btnAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\@" />
<Button
android:id="@+id/btnHash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\#" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private RecyclerView mRecyclerView; // RecyclerVIew
private CheckItemAdapter myAdapterRecyclerView; //The Adapter for RecyclerVIew
Button btnAt, btnHash;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
setAdapter();
btnAt = (Button) findViewById(R.id.btnAt);
btnHash = (Button) findViewById(R.id.btnHash);
}
public void setAdapter() {
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); // Set LayoutManager in the RecyclerView
myAdapterRecyclerView = new CheckItemAdapter(this, getData()); // Create Instance of MyAdapterRecyclerView
mRecyclerView.setAdapter(myAdapterRecyclerView); // Set Adapter for RecyclerView
}
public ArrayList<ItemModel> getData() {
ArrayList<ItemModel> itemModelArrayList = new ArrayList<ItemModel>();
ItemModel itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
itemModel = new ItemModel();
itemModel.setChkText("ABC");
itemModelArrayList.add(itemModel);
return itemModelArrayList;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btnAt) {
//print @ on focused EditText of RecyclerView item
} else if (v.getId() == R.id.btnHash) {
//print # on focused EditText of RecyclerView item
}
}
}
CheckItemAdapter
public class CheckItemAdapter extends RecyclerView.Adapter<CheckItemAdapter.MyViewHolder> {
private ArrayList<ItemModel> mList;
Context context;
public CheckItemAdapter(Context context, ArrayList<ItemModel> mList) {
this.mList = mList;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view
View itemLayoutView = LayoutInflater.from(context).inflate(R.layout.single_check_list, parent, false);
// create ViewHolder
MyViewHolder viewHolder = new MyViewHolder(itemLayoutView);
return viewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
ItemModel itemModel = mList.get(position);
holder.editCheckItem.setText(itemModel.getChkText());
}
@Override
public int getItemCount() {
if (mList != null)
return mList.size();
else
return 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public EditText editCheckItem;
public CheckBox chkItem;
public TextView txtRemove;
public MyViewHolder(View itemLayoutView) {
super(itemLayoutView);
editCheckItem = (EditText) itemLayoutView.findViewById(R.id.editCheckItem);
}
}
}
[![output image][1]][1]