我是新来的,所以这可能很简单,但我到处寻找,无法找出问题所在。我试图清理项目,main.xml 在资源文件夹中,但仍然无法正常工作。我要做的就是在用户输入名称并点击“显示名称”按钮后显示一个对话框。它真的不应该这么难,我已经使用了网上的几个例子,但无法让它发挥作用。任何帮助或正确方向的观点将不胜感激。先感谢您。我第一次发帖,希望我能正确发布我的问题和代码。
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);
}
}
}