我正在尝试制作帮助对话框,它为我的应用用户提供了一些有用的提示。提示应该在@string资源中以处理语言问题。点击时会弹出对话框,其中的文本应该是可滚动的。我目前的实施无法满足这些要求。这是代码:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import ch.OptiLab.visuscontroll.R;
public class MainActivity extends Activity implements OnClickListener {
TextView textView;
Button buttonende;
Button tipps;
Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
tipps = (Button) findViewById(R.id.tipps);
btn1 = (Button) findViewById(R.id.buttonSTART);
buttonende = (Button) findViewById(R.id.buttonende);
btn1.setOnClickListener(this);
tipps.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder (MainActivity.this.getActivity());
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
}
});
答案 0 :(得分:0)
将您的代码更改为
(...)
AlertDialog dialog = builder.create();
dialog.show(); //Do not forget this line
另外,请确保正确初始化构建器:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);