【问题标题】:Undo Button for a WordSearch appWordSearch 应用程序的撤消按钮
【发布时间】:2017-07-13 22:26:29
【问题描述】:

我是 android 新手,很难在我的应用上找到解决问题的方法。

我的应用是一个文字搜索游戏,它使用点击图块作为输入。这是tablelayout上动态textviewsonClick()的代码:

text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    w.setVisibility(View.VISIBLE);

                    //change the color of tapped textview

                    text.setTextColor(Color.WHITE);
                    text.setBackgroundColor(Color.parseColor(mColors[randomNum]));

                    String b = text.getText().toString();

                    uTxt.setText(""+uTxt.getText().toString() + b);

                    //check if answer is in the word grid


                    if(checkAns(uTxt, list))
                    {


                        w.setVisibility(View.GONE);
                        wC.setText(String.valueOf(Integer.parseInt(wC.getText()+"")-1));

                        if(Integer.parseInt(wC.getText()+"") == 0){

                            int newM = minutes*60 + seconds;
                            dataHelper.insertData(pNameC.getText().toString(), newM, currentDateandTime, Category.leve);

                            t.cancel();
                            Context mContext = getApplicationContext();
                            Activity mActivity = GameScreen.this;
                            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);

                            // Inflate the custom layout/view
                            View customView = inflater.inflate(R.layout.gameover,null);

                            // Initialize a new instance of popup window
                            PopupWindow mPopupWindow = new PopupWindow(
                                    customView,
                                    RelativeLayout.LayoutParams.MATCH_PARENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT
                            );

                            Typeface font = Typeface.createFromAsset(getAssets(), "raw2.ttf");
                            TextView cattxt = (TextView)customView.findViewById(R.id.catTxt);


                            String ctg = ti.getText().toString();

                            cattxt.setTypeface(font);
                            cattxt.setText(ctg);



                            Button yesB = (Button) customView.findViewById(R.id.maglaro2);
                            yesB.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Intent intent = new Intent(GameScreen.this, Category.class);
                                    startActivity(intent);
                                    overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
                                    GameScreen.this.finish();
                                }
                            });

                            Button noB = (Button) customView.findViewById(R.id.hindi);
                            noB.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent intent = new Intent(GameScreen.this, MainActivity.class);
                                    startActivity(intent);
                                    overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
                                    GameScreen.this.finish();
                                }
                            });

                            mPopupWindow.showAtLocation(table, Gravity.CENTER,0,0);
                        }
                        uTxt.setText("");

                    }




                    }

            });

现在我的问题是我想要一个 UNDO 按钮,它会删除 uTxt 上的最后一个字符,并将最后一次触摸的颜色改回 textView

有人对如何做到这一点有任何想法吗?

如果是,请在下方留下评论、答案或建议。蒂亚!

【问题讨论】:

  • 你听说过堆栈吗?
  • @RobertColumbia 还没有:)

标签: android textview undo


【解决方案1】:

此问题的典型解决方案是使用命令模式(非常适合撤消重做功能)。 见https://en.wikipedia.org/wiki/Command_pattern

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    相关资源
    最近更新 更多