これについては、できるだけ早く説明します。ボタンのテキストからのコンプベーションが必要なアプリを開発しています。コードで説明しましょう。ボタンに「このテキスト」がある場合は、それを行います。私は過去 2 日間、いくつかの異なることを試みてきましたが、行き詰まっているので、質問しています。これが私のコードです:
XML:
<Button
android:id="@+id/bHiddenL1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_margin="18dp"
android:text="@string/NotUsed"
android:maxLength="10" />
ジャワ:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newnotebookbutton);
initializeNotebookNewSubject();
}
public void initializeNotebookNewSubject() {
NewTextInput = (EditText) findViewById(R.id.etNewNotebookButtonCreateSubjectButton);
OKButton = (Button) findViewById(R.id.bOkButton);
Button1L = (Button) findViewById(R.id.bHiddenL1);
Button2L = (Button) findViewById(R.id.bHiddenL2);
Button3L = (Button) findViewById(R.id.bHiddenL3);
Button4L = (Button) findViewById(R.id.bHiddenL4);
Button5L = (Button) findViewById(R.id.bHiddenL5);
Button1R = (Button) findViewById(R.id.bHiddenR1);
Button2R = (Button) findViewById(R.id.bHiddenR2);
Button3R = (Button) findViewById(R.id.bHiddenR3);
Button4R = (Button) findViewById(R.id.bHiddenR4);
Button5R = (Button) findViewById(R.id.bHiddenR5);
OKButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String b1L = Button1L.getText().toString();
String b2L = Button2L.getText().toString();
String b3L = Button3L.getText().toString();
String b4L = Button4L.getText().toString();
String b5L = Button5L.getText().toString();
String b1R = Button1R.getText().toString();
String b2R = Button2R.getText().toString();
String b3R = Button3R.getText().toString();
String b4R = Button4R.getText().toString();
String b5R = Button5R.getText().toString();
if(b1L == "Not Used" && NewTextInput.getText().toString() != null){
NewSubjectBundle.putString("title1L", NewTextInput.getText().toString());
NewSubjectBundle.putInt("int", 1);
mIntent.putExtras(NewSubjectBundle);
setResult(RESULT_OK, mIntent);
finish();
私の問題をよりよく特定させてください。「String b1L = Button1L.getText().toString();」を実行しようとすると、logcat にポインターが Null であるというエラーが表示されます。それはどのように修正する必要がありますか?