Я пытаюсь выучить тонкости и выходов Android , и я нахожу некоторые реальные проблемы. Я пытаюсь связать кнопку с TextView , когда вы нажимаете кнопку значение в изменении TextView . Я попытался использовать часть примера кода, который я нашел в Интернете, но я получаю много ошибок, и я не уверен, что с ними делать. Я бы признателен за любую помощь, которую вы могли бы предложить.Multiple markers at this line
- main cannot be resolved or is not a field
- R cannot be resolved to a variable
< /code>
в строке 29: < /p>
btn1 cannot be resolved or is not a field
< /code>
at line 32: < /p>
Syntax error on token(s), misplaced construct(s)
< /code>
в строке 34: < /p>
Multiple markers at this line
- Syntax error on token ")", ; expected
- Syntax error on token "(", ; expected
- void is an invalid type for the variable onClick
< /code>
в строке 36: < /p>
txtVw1 cannot be resolved or is not a field
< /code>
А затем мой код: < /p>
package com.demuro1.views;
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Button aBut = (Button) findViewById(R.id.btn1);
public void changeText(){
mButton.setOnClickListener(new View.OnClickListener {
public void onClick(View v) {
final TextView mTextView = (TextView) findViewById(R.id.txtVw1);
mTextView.setText("Some Text");
}
};
}
}
< /code>
, а затем xml < /code> из представления < /p>
/>
Подробнее здесь: https://stackoverflow.com/questions/231 ... in-android