撤消WordSearch应用程序的按钮

时间:2017-02-23 12:27:35

标签: android textview undo

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

我的应用是一款wordsearch游戏,使用点击图块作为输入。这是tablelayout上动态 textviews onClick()代码:

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的颜色

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

如果是,请在下面留下评论,回答或建议。 TIA!

1 个答案:

答案 0 :(得分:1)

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

相关问题