我想通过setOnClickListener(android studio)对Java代码进行单元测试,但我做不到!有人可以给我一些例子吗?
public class MainActivity extends AppCompatActivity {
private Button btnStart;
private Button btnConsult;
private Button btnSales;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Call the SQLite Connection
ConnectionSQLite.getInstance(this);
this.btnStart = (Button) findViewById(R.id.btnStart);
this.btnConsult = (Button) findViewById(R.id.btnConsult);
this.btnSales = (Button) findViewById(R.id.btnSales);
// The button to start the application
this.btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ProductActivity.class);
startActivity(intent);
}
});
// The button to consult the list of products
this.btnConsult.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ProductListActivity.class);
startActivity(intent);
}
});
// The button to buy products
this.btnSales.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SalesActivity.class);
startActivity(intent);
}
});
}
}