in Education by
I want to change the images in image view on Onclick function. I have already tried this: bt_audiocapture.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (checkPermission()) { if (bt_audiocapture.getResources().getDrawable(R.drawable.ic_mic).equals(R.drawable.ic_mic)) { start(); bt_audiocapture.setImageResource(R.drawable.ic_stop); } else if (bt_audiocapture.getResources().getDrawable(R.drawable.ic_stop).equals(R.drawable.ic_stop)) { stop(); bt_audiocapture.setImageResource(R.drawable.ic_play); } else if (bt_audiocapture.getResources().getDrawable(R.drawable.ic_play).equals(R.drawable.ic_play)) { play(); } } } }); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
bt_audiocapture.getResources().getDrawable(R.drawable.ic_mic) returns a Drawable object. You can't compare it to R.drawable.ic_mic, which is integer. That is something like comparing a car to green color. To accomplish your task, make some field like private int state = 0;, and some constants like private final STATE_PLAYING = 1; private final STATE_STOPPED = 2; private final STATE_NONE = 0; and then: if (state == STATE_NONE) { start(); bt_audiocapture.setImageResource(R.drawable.ic_stop); state = STATE_PLAYING; } else if (state == STATE_PLAYING) { stop(); bt_audiocapture.setImageResource(R.drawable.ic_play); state = STATE_STOPPED; } else if (state == STOPPED) { play(); state = STATE_PLAYING; }

Related questions

0 votes
    How to remove a image in imageview in android and also how to hide the entire image. Here I have ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    Hello I am using native UITableViewCell in my UITableView. When I set the image of the cell it looks ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    Since I can't intercept action_down event for gridview, I would like to get (x,y) coordinate of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    I'm attempting to automate a payment system, where the "Pay with PayPal" button is within an iFrame. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have this bit of javascript written with jQuery 1.2.5. It's contained inside the main function( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I have this bit of javascript written with jQuery 1.2.5. It's contained inside the main function( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Here's a code snippet. . . Yes No Clearly, what I'm trying to do is call the routine linked to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have one aspx page with 1000 anchor tag. I want to open single popup onclick of anchor tag & ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    I have a table like below 11 12 13 11 12 13 11 12 13 After I click on the table, I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a table like below 11 12 13 11 12 13 11 12 13 After I click on the table, I ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Based on Raphael demo: http://raphaeljs.com/australia.html I have created objects that changes their colour. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    How many kinds of reflection are available in image perception? (a) 1 (b) 2 (c) 3 (d) 4 Please answer the above question....
asked Oct 22, 2022 in Education by JackTerrance
...