Android - 如何从另一个方法获取值字符串?

时间:2017-08-30 21:11:09

标签: java android

MainActivity.class

public class MainActivity extends AppCompatActivity {
....

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    .....

    Button btnGenerate = (Button) findViewById(R.id.btn_generate);
    etInput = (EditText) findViewById(R.id.input_username);
    tvTampil = (TextView) findViewById(R.id.tittle);

    btnGenerate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showProgressDialog();
            tvTampil.setText(etInput.getText().toString());
            anjay = tvTampil.getText().toString();
        }
    });
}

private void showProgressDialog() {

    final MaterialStyledDialog.Builder popup = new MaterialStyledDialog.Builder(context)
            .setTitle(anjay)
            .setDescription("Please check your diamond and battle point now")
            .setPositiveText("Thanks");

    ....

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            progressDialog.dismiss();
            popup.show();
        }
    }, 3000);
}

我使用我的编码,但没有出现。 我想将值edittext发送到.setTittle MaterialStyledDialog。

感谢

1 个答案:

答案 0 :(得分:0)

获取您正在制作的编辑文字,但将其作为参数传递给showProgressDialog()函数。

   @Override
    public void onClick(View view) {
        showProgressDialog(etInput.getText().toString());
        tvTampil.setText(etInput.getText().toString());
        anjay = tvTampil.getText().toString();
    }

只需更改您的功能即可获取此类参数

    public void showProgressDialog(String title) {
        final MaterialStyledDialog.Builder popup = new MaterialStyledDialog.Builder(context)
        .setTitle(title)
        ...

    }