У меня есть главная страница с двумя кнопками, кнопка 1 включена, а кнопка2 отключена. button1 откроет 2-ю страницу, которая имеет 1 кнопку с именем button3. button3 будет нажимать BACK на главную страницу, и она должна активировать кнопку2. проблема в том, что кнопка2 станет включенной на короткий период, а затем обратно к отключению (заштрихован).Настройка кнопки включена
Главная страница.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Enable extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enable);
Button page1 = (Button) findViewById(R.id.button1);
page1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), p2.class);
startActivityForResult(myIntent, 0);
}
});
Button page2 = (Button) findViewById(R.id.button2);
page1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), p2.class);
startActivityForResult(myIntent, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_enable, menu);
return true;
}
}
вторая страница
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class p2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.p2);
Button page1 = (Button) findViewById(R.id.button3);
page1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Enable.class);
setContentView(R.layout.activity_enable);
Button a = (Button) findViewById(R.id.button2);
a.setEnabled(true);
startActivityForResult(myIntent, 0);
}
});
}
}
XML главной страницы
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Enable" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="104dp"
android:layout_marginTop="32dp"
android:text="Button" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="46dp"
android:enabled="false"
android:text="Button" />
XML из page2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
У кого-нибудь есть решение для этого? – Jerome
Я практически дал вам один. Я не собираюсь делать ваш код для вас - вы узнаете гораздо больше, изучая все это самостоятельно, и поверьте мне, это намного больше удовлетворяет –