我正在尝试打开一个镀铬窗口,留出足够的时间播放来自YouTube的剪辑,然后关闭Chrome窗口,所有这些都在C#中。我对编码比较陌生,而且我很茫然。
package com.jz.myapp1;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
Button b1 = (Button)findViewById(R.id.b1);
Button b2 = (Button)findViewById(R.id.b2);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("db", "R.id.b1: " + findViewById(R.id.b1).toString() + " R.id.b2: " + findViewById(R.id.b2));
//This generates a NullPointerException, so it is commented out
//Log.i("db", "b1: " + b1.toString() + " b2: " + b2.toString());
/*
When this code runs, it is reported that b1 and/or b2 are null,
despite the fact that they are both defined in activity_main.xml.
For this reason, the OnClickListner is never set for the buttons.
What is the problem?
*/
if ((b1==null) || (b2==null))
{
Log.i("db", "b1 and/or b2 are null");
}
else
{
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
}
@Override
public void onClick(View v)
{
TextView tv2 = (TextView)findViewById(R.id.tv2);
if (v.getId() == R.id.b1)
{
tv2.setText("You have chosen Choice #1");
}
else if (v.getId() == R.id.b2)
{
tv2.setText("You have chosen Choice #2");
}
}
}
在Thread.Sleep关闭浏览器窗口而不关闭程序后,我可以添加什么?
答案 0 :(得分:0)
p1.CloseMainWindow();
p1.Close();
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.close(v=vs.110).aspx