5秒后显示对话框

时间:2015-10-13 17:28:45

标签: android

我希望在此活动中5秒后打开费率对话框......源代码应该是什么以及我应该在哪里申请?

public class Link extends AppCompatActivity 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setLogo(R.drawable.ic_launcher);
        getSupportActionBar().setDisplayUseLogoEnabled(true);
        setContentView(R.layout.link);

    }
}

这是费率对话框

public class Rate extends Dialog{

    Button rate,bad,flag,lol,late;
    Activity c;

    public Rate(Context context, myOnClickListener myclick) {
        super(context);
        this.myListener = myclick;
    }
    public Rate(Activity activity)
    {
        super(activity);
        c = activity;
    }
    public myOnClickListener myListener;

    // This is my interface //
    public interface myOnClickListener {
        void onButtonClick();
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.rate);

        rate = (Button)findViewById(R.id.btnYes);
        bad = (Button)findViewById(R.id.ratebad);
        flag = (Button)findViewById(R.id.flags);
        lol =(Button)findViewById(R.id.lolli);
        late = (Button)findViewById(R.id.later);

        rate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=com.aio.amar.tricks"));
                c.startActivity(i);
            }
        });

        bad.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent a = new Intent("android.intent.action.SEND");
                a.setType("text/html");
                a.putExtra("android.intent.extra.EMAIL", new String[] {c.getString(R.string.mail_feedback_emai)});
                a.putExtra("android.intent.extra.SUBJECT", c.getString(R.string.mail_feedback_subjec));
                a.putExtra("android.intent.extra.TEXT", c.getString(R.string.mail_feedback_messag));
                c.startActivity(Intent.createChooser(a, c.getString(R.string.title_send_feedbac)));
            }
        });

        flag.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent b = new Intent("android.intent.action.SEND");
                b.setType("text/html");
                b.putExtra("android.intent.extra.EMAIL", new String[] {c.getString(R.string.


mail_feedback_email)});
                b.putExtra("android.intent.extra.SUBJECT", c.getString(R.string.mail_feedback_subject));
                b.putExtra("android.intent.extra.TEXT", c.getString(R.string.mail_feedback_message));
                c.startActivity(Intent.createChooser(b, c.getString(R.string.title_send_feedback)));

            }
        });
        lol.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=com.dfc.aef"));
                c.startActivity(i);

            }
        });

        late.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismiss();
            }
        });

    }

}

2 个答案:

答案 0 :(得分:1)

要在延迟一段时间后运行代码,您可以使用Handler

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    // put some code
    // it will run after 5000 milliseconds
  }
}, 5000);

将其放入onCreate方法

答案 1 :(得分:0)

将这样的处理程序放在onResume()方法的结尾

var names = fullName.Split(' ');
        var formatted = new StringBuilder();
        foreach(string name in names)
        {
            if(name.Contains('-'))
            {
                var nonHyphanatedNames = name.Split('-');
                    foreach (var nonHyphanatedName in nonHyphanatedNames)
                    {
                        formatted.Append(char.ToUpper(nonHyphanatedName[0]) + nonHyphanatedName.Substring(1).ToLower() + '-');
                    }

            }
            else
            {
                formatted.Append(char.ToUpper(name[0]) + name.Substring(1).ToLower() + ' ');
            }


        }
        //remove last field
        formatted.Remove(formatted.Length - 1, 1);
        Console.Write(formatted);