Я добавил переключатель в свой андроид xml, у меня также есть несколько блоков Edit_text, скажем 9 в том же действии. Моя цель - сделать их видимыми одним щелчком мыши. И вот идет мой код Java:Почему в моем коде не работает макет андроида?
public class MainActivity extends ActionBarActivity {
//static int count = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Switch mySwitch = (Switch)findViewById(R.id.switchButton);
mySwitch.setChecked(true);
mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{
LinearLayout pop = (LinearLayout)findViewById(R.id.linear);
pop.setVisibility(View.VISIBLE);
}
else
{
LinearLayout pop = (LinearLayout)findViewById(R.id.linear);
pop.setVisibility(View.INVISIBLE);
}
}
});
}
И проблема в том, что, когда я запускаю это в устройстве/эмуляторе я не могу изменить состояние переключателя. Любая помощь будет оценена. :)
код XML:
<RelativeLayout xmlns:>
<Switch
android:id="@+id/switchButton"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:switchMinWidth="14.5sp"
android:switchPadding="14.5sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editTextOne"
android:layout_marginTop="150dp"
android:background="#1ec0e9"
android:alpha="0.5"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/editTextTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:background="#cacaca"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextThree"
android:background="#1ec0e9"
android:alpha="0.5"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/editTextFour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:background="#cacaca"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextFive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1ec0e9"
android:alpha="0.5"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextSix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:background="#cacaca"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextSeven"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1ec0e9"
android:alpha="0.5"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextEight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.6"
android:background="#cacaca"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
<EditText
android:id="@+id/editTextNine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1ec0e9"
android:alpha="0.5"
android:ems="13"
android:gravity="left"
android:typeface="monospace"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Post ваш макет XML .. –
Почему вы инициализации '' pop' LinearLayout' дважды? Вы можете инициализировать его только один раз в своем 'onCreate'. – iRuth
Я хочу сказать, что полная компоновка, я хочу видеть, что есть только один макет родителя или вы помещаете свои дочерние представления, то есть редактируете текст в другом макете в разделе «Родительский макет». –