Es gibt eine EditText
und eine Button
innerhalb eines Activity
nach einigen Text innerhalb eines EditText
Eingabe und Button wird eine Methode aufgerufen und übergibt Gehalt an EditText
ein Verfahren wie unten:kann den editView-Inhalt nicht an eine Methode übergeben, warum?
public class MainActivity extends AppCompatActivity {
TextView txt_title;
Button btn_send;
EditText edt_notification;
public final static String NOTIFICATION_DATA="NOTIFICATION_DATA";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt_title= (TextView) findViewById(R.id.txt_title);
edt_notification= (EditText) findViewById(R.id.edt_notification);
btn_send= (Button) findViewById(R.id.btn_send);
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SendNotification(Calendar.getInstance().getTimeInMillis(), edt_notification.getText().toString());
}
});
}
private void SendNotification(long timeInMillis, String s) {
Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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="ir.wikichera.badamchi.sendnotification.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txt_title"
android:text="Notification Text:"
android:textSize="18sp"
android:textStyle="normal|bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_below="@+id/txt_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:id="@+id/edt_notification"
android:hint="put your text here"
android:singleLine="false" />
<Button
android:text="Send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edt_notification"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="17dp"
android:id="@+id/btn_send" />
</RelativeLayout>
Das Problem ist variabel "s" gibt mir die ganze Zeit "Kann lokale Variable nicht finden" "". Warum? Dies ist ein einfaches Problem, aber ich kann es nicht verstehen. bitte erkläre?
versuchen SendNotification (Calendar.getInstance(). GetTimeInMillis(), MainActivity.this.edt_notification.getText(). ToString()); – mWhitley
können Sie Layout-XML auch einfügen? – NehaK
müssen Sie den Code debuggen und setzen xml –