package com.example.connectdroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
void myClick(){
//here is my problem:
LinearLayout lView = (LinearLayout)findViewById(R.id.mylinear);
TextView selection = (TextView) findViewById(R.id.editText1);
String mytext = "apple";
selection.setText(mytext);
}
}
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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Button"
android:onClick="myClick" />
<LinearLayout
android:id="@+id/mylinear"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginLeft="17dp"
android:layout_marginTop="57dp" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/mylinear"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="22dp"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:1)
void myClick(){
应该是
public void myClick(View view){
您的应用程序崩溃了,因为您声明了android:onClick="myClick"
但myClick的java文件中的签名错误
答案 1 :(得分:0)
那是真正的亲爱的黑带,
名为onClick的方法应该遵循以下功能