2017-08-30 55 views
1

MainActivity.classAndroid - 如何從另一種方法獲取值字符串?

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

讓您編輯文本就像你正在做的,但把它作爲參數傳遞給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) 
     ... 

    } 
相關問題