0
アクションバーメニューのオプションをチェックした後、レイアウトから一部のボタンのステータスを更新したいとします。レイアウトのコンテンツをアクションバーから更新するにはどうすればよいですか?
私はアクションバーメニューのため、このコードを持っている:ボタンを制御
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int delay = 150; // delay 150 ms.
switch (item.getItemId()){
case R.id.action_disconnect:
data.saveData(this.getApplicationContext());
Disconnect();
return true;
case R.id.action_check:
if (item.isChecked())
{
// here i want to update button status
item.setChecked(false);
ledControl.instance.data.expertMode = false;
ledControl.instance.data.configExpertMode = 1;
ledControl.instance.data.sendConfigTurnLightMessage();
}
else {
item.setChecked(true);
ledControl.instance.data.expertMode = true;
// here i want to update button status
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
そして、ここでは、レイアウトクラスはフラグメント
public class BlinkFragment extends Fragment implements View.OnClickListener {
private Switch switch_b1, switch_b2;
private DiscreteSeekBar discrete_bl_g, discrete_bl_h;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_blink, container, false);
switch_b1 = (Switch) v.findViewById(R.id.switch_b1);
switch_b2 = (Switch) v.findViewById(R.id.switch_b2);
discrete_bl_g = (DiscreteSeekBar) v.findViewById(R.id.discrete_bl_g);
discrete_bl_h = (DiscreteSeekBar) v.findViewById(R.id.discrete_bl_h);
discrete_bl_g.setEnabled(ledControl.instance.data.expertMode);
discrete_bl_h.setEnabled(ledControl.instance.data.expertMode);
}
}
としてロードされて、私はこのような方法を試してみます:
fragment = new BlinkFragment();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment2, fragment);
ft.commit();
私がやりたいことはある: –
私は、フラグメントレイアウト上とでいくつかのボタンがありますアクションバーiのチェックボックスは無効にしてボタンを有効にしますが、レイアウトを再ロードするまで問題はレイアウトには反映されません。 –
[OK]を、あなたの問題を理解したいです。私のコードはあなたのプロジェクトでは機能しませんでしたか? – nshmura