сейчас это моя проблема. У меня есть 2 вида, которые на обоих вы что-то вычислите. Я использую тот же код в обоих представлениях (но с небольшими изменениями, чтобы они не вычисляли одно и то же) Но проблема в том, что кнопка на странице 2 НЕ подсчитывает ничего. Вот код для просмотра Java файл # 2:Кнопка и вычисление в затмении
package tk.iWeld.iweld;
импорт android.os.Bundle; import android.app.Activity;
импорт android.support.v4.view.ViewPager; импортировать android.view.View;
импорт android.widget.EditText; import android.widget.TextView;
общественный класс TestLay расширяет активность {
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.testlayout); } public void StartClickListener(View view) { } public void calculateClickListener(View view) { // make sure we handle the click of the calculator button if (view.getId() == R.id.button) { // get the references to the widgets EditText text1Text = (EditText)findViewById(R.id.editText1); EditText text2Text = (EditText)findViewById(R.id.editText2); TextView resultText = (TextView)findViewById(R.id.resultat); float text1 = Float.parseFloat(text1Text.getText().toString()); float text2 = Float.parseFloat(text2Text.getText().toString()); // calculate the result value float totalresult = calculateRESULT(text1, text2); // now set the value in the result text resultText.setText("Debug=ok" + (totalresult)); } } // the formula to calculate the result index private float calculateRESULT (float text1, float text2) { return (float) (3.14 * (text1 * text1) * text2/4/1000000); } }
Кажется, что я не попасть в кнопку штуковина, потому что я добавил это: – user3210676
TextView RESU = (TextView) findViewById (R .id.textView5); resu.setText («Debug = ok»); И это не изменилось ... Но почему это работает на странице1? – user3210676
Проверьте, действительно ли ваш callClickListener() вызывает вызов. Поместите оператор журнала раньше, если (view.getId() == R.id.button). И проверьте, что такое view.getId(). – Eduard