clicklistener

One OnClickHandler for multiple Buttons

旧巷老猫 提交于 2019-12-17 06:28:48
问题 I find myself doing things like this all the time: Button button1 = (Button) findViewById(R.id.button1); Button button2 = (Button) findViewById(R.id.button2); Button button3 = (Button) findViewById(R.id.button3); button1.setOnClickListener(menuButtonListener); button2.setOnClickListener(menuButtonListener); button3.setOnClickListener(menuButtonListener); ... and private OnClickListener myButtonListener = new OnClickListener() { @Override public void onClick(View v) { switch(v.getId()){ case R

DataGridView click event doesn't always fire

家住魔仙堡 提交于 2019-12-12 14:22:43
问题 I have a DataGridView . Its Cell_Content_Click is not firing each time I select a cell. It does fires but not at each click. I want to get content of selected cell in my string variable 'selected'. Here is what I am doing: private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { selected = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); } } 回答1: The CellContentClick

Android setClickListner outside onCreate

筅森魡賤 提交于 2019-12-04 20:59:56
This is my onCreate function. Since there is lot of code inside onclickListener for Hello i want to shift it outside to a method. how can i do that ? public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); facebook.authorize(this, permissions, Facebook.FORCE_DIALOG_AUTH, new DialogListener() { public void onComplete(Bundle values) { } public void onFacebookError(FacebookError error) { } public void onError(DialogError e) { } public void onCancel() { } }); hello = (Button) findViewById(R.id.hello); info = (TextView) findViewById(R.id

Click Listeners in Loop - Array and Closure

别说谁变了你拦得住时间么 提交于 2019-12-02 20:37:07
问题 I realise I'm treading on thin ice opening another closure issue, but I have searched and can't find an answer to my issue. I have a Google Maps API v3 page which generates two maps from one block of code - a small map centered on the user's current location and a larger map showing the whole area with the user's location marked where it is, center or not. On top of the map is a rectangle layer consisting of 14 rectangles. In order to generate the two maps, I have had to put the rectangles in

One OnClickHandler for multiple Buttons

倾然丶 夕夏残阳落幕 提交于 2019-11-27 00:13:55
I find myself doing things like this all the time: Button button1 = (Button) findViewById(R.id.button1); Button button2 = (Button) findViewById(R.id.button2); Button button3 = (Button) findViewById(R.id.button3); button1.setOnClickListener(menuButtonListener); button2.setOnClickListener(menuButtonListener); button3.setOnClickListener(menuButtonListener); ... and private OnClickListener myButtonListener = new OnClickListener() { @Override public void onClick(View v) { switch(v.getId()){ case R.id.button1 : ... Is there a better way to set the OnClickListener? You can also set it in your layout

Android: Using findViewById() with a string / in a loop

前提是你 提交于 2019-11-26 15:07:57
I'm making an android application, where there is a view composed of hundreds of buttons, each with a specific callback. Now, I'd like to set these callbacks using a loop, instead of having to write hundreds of lines of code (for each one of the buttons). My question is: How can I use findViewById without statically having to type in each button id? Here is what I would like to do: for(int i=0; i<some_value; i++) { for(int j=0; j<some_other_value; j++) { String buttonID = "btn" + i + "-" + j; buttons[i][j] = ((Button) findViewById(R.id.buttonID)); buttons[i][j].setOnClickListener(this); } }