我是新的,所以這可能很簡單,但我已經到處看,無法找出問題。我嘗試清理該項目,main.xml位於資源文件夾中,但仍無法使其工作。我想要做的是在用戶輸入名稱並點擊'show name'按鈕後顯示一個對話框。這真的不應該是這麼難,我已經使用了幾個來自在線的例子,但無法實現它的工作。任何幫助或正確的方向點將不勝感激。先謝謝你。我第一次發帖希望我正確發佈我的問題和代碼。主不能解決到一個類型
package smartTemps.showName.example;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button
import android.widget.EditText;
import android.widget.TextView;
public class ShowNameActivity extends Activity implements View.OnClickListener
{
public String name;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//display dialog with button click
//create button and register as listener
Button submitButton = (Button)findViewById(R.id.submitButton);
submitButton.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout.maindialog);
//builder.setIcon(R.drawable.btn_star);
dialog.setTitle("User's name");
dialog.setCancelable(true);
//get user name
EditText inputName = (EditText)findViewById(R.id.inputName);
name = inputName.getText().toString();
TextView userName = (TextView)findViewById(R.id.userName);
//set user name label
userName.setText("Welcome, " + name);
Button submitButton = (Button) findViewById(R.id.submitButton);
}
}
}