小编Dyn*_*yna的帖子

Android - 每5秒循环一部分代码

当我按下按钮START并按下按钮STOP时,我想每5秒开始重复两行代码.我尝试使用TimerTask和Handles,但无法弄清楚如何.

public class MainActivity extends Activity {




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


           //final int i;
           final TextView textView = (TextView) findViewById(R.id.textView);
           final Button START_STOP = (Button) findViewById(R.id.START_STOP);
           final ImageView random_note = (ImageView) findViewById(R.id.random_note);
           final int min = 0;
           final int max = 2;
           final Integer[] image = { R.drawable.a0, R.drawable.a1,R.drawable.a2 };



        START_STOP.setTag(1);
        START_STOP.setText("START");


        START_STOP.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            int status = (Integer) v.getTag();
            if (status ==1) {
                textView.setText("Hello");
                START_STOP.setText("STOP");
                v.setTag(0);

                final Random random …
Run Code Online (Sandbox Code Playgroud)

android loops timer handlers timertask

8
推荐指数
3
解决办法
4万
查看次数

插入多个字符时关闭文本字段

我有一个文本字段,我想插入一个电话号码.问题是我使用数字键盘,没有任何输入键,我没有该键,我不知道如何关闭文本字段.

是否有任何方法可以检查文本字段中有多少个字符,并在有字符时关闭数字键盘?

对不起我的英语和抱歉的noob问题,但我刚开始与ObjC.

谢谢*

对不起伙计们,我忘了告诉你我已经尝试过了:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    if (textField.text.length== 9) {
         [textField resignFirstResponder];

    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

objective-c uitextfield ios

5
推荐指数
1
解决办法
1843
查看次数

标签 统计

android ×1

handlers ×1

ios ×1

loops ×1

objective-c ×1

timer ×1

timertask ×1

uitextfield ×1