和以前一样,我正在做一些教程,但我认为我重写的那个我在重写代码时犯了一些错误。在指南的这一部分中,我应该添加两个按钮。我已经完成了所有步骤,但是:
bottone1 无法解析或不是字段
bottone2 无法解析或不是字段
这是代码:
package marco.prova;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.view.View;
public class Main extends Activity {
private TextView textView1;
private Button bottone1;
private Button bottone2;
/** Called when the activity is first created.*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1 = (TextView) findViewById(R.id.testo1);
textView1.setText("Testo modificato tramite codice 1");
bottone1 = (Button) findViewById(R.id.bottone1);
bottone2 = (Button) findViewByid(R.id.bottone2);
bottone1.setOnClickListener(new View.OnClickListener() {
public void onClick (View view) {
textView1.setText("E' stato premuto il bottone 1");
}
});
bottone2.setOnClickListener(new View.OnClickListener() {
public void onClick (View view) {
textView1.setText("E' stato premuto il bottone 1");
}
});
}
}
希望得到一些帮助。谢谢你。
这里是layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> >
<TextView
android:text="Testo di default TextView1"
android:id="@+id/testo1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Button
android:text="Bottone1"
android:id="@+id/bottone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Bottone2"
android:id="@+id/bottone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>