Android:使用递增整数部分将数据保存到字符串变量

Android:使用递增整数部分将数据保存到字符串变量,android,sqlite,Android,Sqlite,我试图在按下按钮时将配方名称所选的星期几以及所选的日期和星期几分配给SQLite表,每次按下按钮时,我希望此表的配方名称保存到名为plan_recipe1的变量,但每次增加1,直到plan_recipe2、plan_recipe3等。然后,这些内容也将与用户输入的计划名称一起保存。我不知道该怎么做,到目前为止,这就是我所拥有的,我只是失去了它,感到困惑 到目前为止的代码 public class CreateMealPlan extends MainActivity { DatePicker

我试图在按下按钮时将配方名称所选的星期几以及所选的日期和星期几分配给SQLite表,每次按下按钮时,我希望此表的配方名称保存到名为plan_recipe1的变量,但每次增加1,直到plan_recipe2、plan_recipe3等。然后,这些内容也将与用户输入的计划名称一起保存。我不知道该怎么做,到目前为止,这就是我所拥有的,我只是失去了它,感到困惑

到目前为止的代码

public class CreateMealPlan extends MainActivity {

DatePicker datepicker;
Button submit;
Button addrecipe;
List<com.stu54259.plan2cook.Model.Category> listRecipe = new ArrayList<>();
//SQLiteDatabase db;
Cursor c;
RecyclerView recipeList;
RecipeListAdapter adapterRecipe;
String recipe_name;
EditText editPlanName;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_meal_plan);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.home:
                    Intent a = new Intent(CreateMealPlan.this,MainActivity.class);
                    startActivity(a);
                    break;
                case R.id.recipes:
                    Intent b = new Intent(CreateMealPlan.this,RecipeSearch.class);
                    startActivity(b);
                    break;
                /*case R.id.shoppingList:
                    Intent c = new Intent(CreateMealPlan.this, ShoppingList.class);
                    startActivity(c);
                    break;*/
                case R.id.mealPlan:
                    Intent d = new Intent(CreateMealPlan.this, MenuPlan.class);
                    startActivity(d);
                    break;
                /*case R.id.reminder:
                    Intent e = new Intent(CreateMealPlan.this, Reminder.class);
                    startActivity(e);
                    break*/
            }
            return false;
        }
    });
    datepicker = findViewById(R.id.calendarView);
    ListRecipes();
    RecipeListAdapter.OnRecipeClickListener listener = new RecipeListAdapter.OnRecipeClickListener() {
        public void onRecipeClicked(int position, String recipe_name) {
            Log.d("Here is the data:",  recipe_name);
        }
    };
    adapterRecipe = new RecipeListAdapter(this, listRecipe, listener);
    recipeList = findViewById(R.id.recipes);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this,
            LinearLayoutManager.VERTICAL, false);
    recipeList.setLayoutManager(mLayoutManager);
    recipeList.setItemAnimator(new DefaultItemAnimator());
    recipeList.setAdapter(adapterRecipe);

    submit = (Button) findViewById(R.id.create);
    addrecipe = (Button) findViewById(R.id.addRecipe);
    addrecipe.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CreatePlansRecipes();


        }

    });
    // perform click event on submit button
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CreatePlan();

        }

        });
}
public void ListRecipes() {
    listRecipe.clear();
    SQLiteDatabase db = (new DatabaseManager(this).getWritableDatabase());
    String selectQuery = " SELECT recipe_name, image, image2, category" + " FROM " + DatabaseManager.TABLE_RECIPE + "  GROUP BY recipe_name";
    c = db.rawQuery(selectQuery, null);
    Log.d("Query", selectQuery);
    if (c.moveToFirst()) {
        do {
            com.stu54259.plan2cook.Model.Category category = new com.stu54259.plan2cook.Model.Category();
            category.setRecipe_name(c.getString(c.getColumnIndex("recipe_name")));
            category.setImage(c.getInt(c.getColumnIndex("image")));
            category.setImage2(c.getString(c.getColumnIndex("image2")));
            category.setCategory_name(c.getString(c.getColumnIndex("category")));
            listRecipe.add(category);
        } while (c.moveToNext());
        c.close();
    }

}
public void CreatePlansRecipes(){
    DatabaseManager db;
    int day = datepicker.getDayOfMonth();
    int month = datepicker.getMonth();
    int year = datepicker.getYear();
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
    Date d_name = new Date(day, month, year);
    String dayOfTheWeek = sdf.format(d_name);
    db = new DatabaseManager(getApplicationContext());
    db.createPlanRecipe(d_name, dayOfTheWeek, recipe_name);
    String Plan_recipe = "plan_recipe1";
    String newPlanName = "plan_recipe" + (Integer.parseInt(Plan_recipe.substring(1,Plan_recipe.length()))+1);
    newPlanName = recipe_name;


}
public void CreatePlan () {
    editPlanName = findViewById(R.id.editPlanName);
    String plan_name = editPlanName.getText().toString();
    DatabaseManager db;
    db = new DatabaseManager(getApplicationContext());
    db.createPlan(plan_name, plan_recipe1, plan_recipe2, plan_recipe3, plan_recipe4, plan_recipe5, plan_recipe6,
            plan_recipe7, plan_recipe8, plan_recipe9, plan_recipe10);


}
public类CreateMealPlan扩展main活动{
日期选择器;
按钮提交;
按钮添加配方;
List listRecipe=新建ArrayList();
//sqlitedb数据库;
光标c;
RecyclerView recipeList;
RecipeListAdapterRecipe;
字符串名称;
EditText editPlanName;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.create_Dine_plan);
BottomNavigationView导航=(BottomNavigationView)findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(新的BottomNavigationView.OnNavigationItemSelectedListener(){
@凌驾
公共布尔值onNavigationItemSelected(@NonNull MenuItem item){
开关(item.getItemId()){
案例R.id.home:
意图a=新意图(CreateMealPlan.this,MainActivity.class);
星触觉(a);
打破
案例R.id.配方:
意图b=新意图(CreateMealPlan.this,RecipeSearch.class);
星触觉(b);
打破
/*案例R.id.购物清单:
意图c=新意图(CreateMealPlan.this,ShoppingList.class);
星触觉(c);
中断*/
案例R.id.mealPlan:
Intent d=新Intent(CreateMealPlan.this,MenuPlan.class);
星触觉(d);
打破
/*案例R.id.提醒:
意向e=新意向(CreateMealPlan.this,rementer.class);
星触觉(e);
中断*/
}
返回false;
}
});
datepicker=findViewById(R.id.calendarView);
ListRecipes();
RecipeListAdapter.OnRecipeClickListener侦听器=新RecipeListAdapter.OnRecipeClickListener(){
RecipeClicked上的公共void(int位置,字符串配方\名称){
Log.d(“这是数据:”,配方名称);
}
};
adapterRecipe=新的RecipeListAdapter(此、listRecipe、侦听器);
recipeList=findViewById(R.id.配方);
RecyclerView.LayoutManager mLayoutManager=新的LinearLayoutManager(此,
LinearLayoutManager.VERTICAL,false);
recipeList.setLayoutManager(mLayoutManager);
recipeList.setItemAnimator(新的DefaultItemAnimator());
recipeList.setAdapter(adapterRecipe);
提交=(按钮)findViewById(R.id.create);
addrecipe=(按钮)findViewById(R.id.addrecipe);
addrecipe.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
CreatePlansRecipes();
}
});
//在提交按钮上执行单击事件
submit.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
CreatePlan();
}
});
}
公共无效列表配方(){
listRecipe.clear();
SQLiteDatabase db=(新数据库管理器(this).getWritableDatabase());
String selectQuery=“从“+DatabaseManager.TABLE\u recipe+”中选择配方名称、图像、图像2、类别“+”;
c=db.rawQuery(selectQuery,null);
Log.d(“查询”,选择查询);
if(c.moveToFirst()){
做{
com.stu54259.plan2cook.Model.Category Category=新建com.stu54259.plan2cook.Model.Category();
category.setRecipe_name(c.getString(c.getColumnIndex(“recipe_name”));
类别.setImage(c.getInt(c.getColumnIndex(“image”));
category.setImage2(c.getString(c.getColumnIndex(“image2”));
category.setCategory_名称(c.getString(c.getColumnIndex(“category”));
添加(类别);
}而(c.moveToNext());
c、 close();
}
}
公共void CreatePlansRecipes(){
数据库管理器数据库;
int day=datepicker.getDayOfMonth();
int month=datepicker.getMonth();
int year=datepicker.getYear();
SimpleDataFormat sdf=新的SimpleDataFormat(“EEEE”);
日期d_name=新日期(日、月、年);
字符串dayOfWeek=sdf.format(d_名称);
db=新数据库管理器(getApplicationContext());
db.createPlanRecipe(d_名称、星期几、配方名称);
字符串Plan\u recipe=“Plan\u recipe1”;
字符串newPlanName=“plan_recipe”+(Integer.parseInt(plan_recipe.substring(1,plan_recipe.length())+1);
newPlanName=配方名称;
}
公共计划(){
editPlanName=findViewById(R.id.editPlanName);
String plan_name=editPlanName.getText().toString();
数据库管理器数据库;
db=新数据库管理器(getApplicationContext());
db.createPlan(计划名称、计划副本1、计划副本2、计划副本3、计划副本4、计划副本5、计划副本6、,
计划副本7、计划副本8、计划副本9、计划副本10);
}
}