My app has a recycler view with a checkbox. I want a notification to show up when box is checked. And save state is appreciated. I've written part of the things I want. But I need your help to get the thing done.
Here's my adapter
public class settingsadapter extends RecyclerView.Adapter<settingsadapter.MyViewHolder> {
private List<settingsitem> settingsitemList;//Well some basic adapter stuff
public settingsadapter(List<settingsitem> settingsitemList) {
this.settingsitemList = settingsitemList;//cause most tutorial online didnt work for me
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.settingsrow, parent, false);//and make this activity crash
return new MyViewHolder(itemView);//this recyclerview has only 1 item
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final int pos = position;//so just 1 checkbox
settingsitem settingsitem = settingsitemList.get(position);
holder.title.setText(settingsitem.getTitle());
holder.emoticons.setText(settingsitem.getEmoticons());//check and comes the notification
}
@Override
public int getItemCount() {
return settingsitemList.size();// save state for the checkbox is needed too
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title, emoticons;
public CheckBox cb1;//I don't know why those tutorial didn't work most of the time
private final Context context;//I never really learned java
public MyViewHolder(View view) {
super(view);//so i have to seek help here
context = itemView.getContext();//really hope you guys can help me
title = (TextView) view.findViewById(R.id.title);
emoticons = (TextView) view.findViewById(R.id.emoticons);
cb1 = (CheckBox) view.findViewById(R.id.notificationchk);
}
}//end of adapter
}
activity java
public class Settings extends AppCompatActivity {
private List<settingsitem> settingsitemList = new ArrayList<>();
private RecyclerView recyclerView;//and now the activity java
private settingsadapter mAdapter;
CheckBox cb1;
NotificationManager manager;//some basic recycler stuff
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);// nothing much here
setContentView(R.layout.activity_settings);
recyclerView = (RecyclerView) findViewById(R.id.settings);
mAdapter = new settingsadapter(settingsitemList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);// I am a newbie
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setAdapter(mAdapter);// there's so much I dont understand
preparesettingsitemData();//hope you understand
}
private void preparesettingsitemData() {
settingsitem settingsitem = new settingsitem(getString(R.string.notification), getString(R.string.notificationexplain), Settings.class);
settingsitemList.add(settingsitem);//Helps are appreciated
mAdapter.notifyDataSetChanged();//Thanks a lot for your help
}//end of main java
}
Aucun commentaire:
Enregistrer un commentaire