[英]Input from one class and output in another?
我正在開發一個android應用程序。 我想要這樣,以便當用戶創建帳戶時,應用程序從New成員類中獲取用戶輸入,並在另一個類中創建輸出。 例如,用戶輸入他們的姓名。 在完全不同的類的應用程序主屏幕上,他們可以看到“您好%name%!您今天想做什么?”,這里有我的新用戶類。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class NewScreen extends Activity {
EditText textEdit4;
EditText textEdit5;
EditText editText3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newscreen);
textEdit4 = (EditText) findViewById(R.id.textEdit4);
textEdit5 = (EditText) findViewById(R.id.textEdit5);
editText3 = (EditText) findViewById(R.id.editText3);
Button btn_submit = (Button) findViewById(R.id.btn_submit);
btn_submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClassName("net.contents.fbla", "net.contents.fbla.NewScreen2");
startActivity(intent);
}
});
}
}
`
和我所說的類的XML
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email_string" />
<EditText
android:id="@+id/textEdit4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pass_string" />
<EditText
android:id="@+id/textEdit5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_submit" />
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
任何幫助都可以! 謝謝-傑里米
您確實需要將所有類都放在一個包中。 Android-在Eclipse的src文件夾中的包名稱約定 ,您可能已經在默認包中包含了類,這不好。 按照約定,在src下創建一個新程序包,該程序包的名稱是網站的反向URL,因為這肯定是唯一的,僅使用期限而不是slash.example com.stackoverflow。 現在在您的源代碼中添加包com.stackoverflow; 作為您java。的第一行,請勿使用stackoverflow,因為這是一個示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.