0

am working in android. Am using NumberPicker which i got from here i want the input value taken from the NumberPicker should be displayed in the TextView which i have written in different class.. how can i do this.. please help.. here is a code..

public class home_try extends Activity {

private NumberPicker numberpicker;

@Override
protected void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);
setContentView(R.layout.dummy1);
final Dialog textDialog = new Dialog(this); 
Button setpoint= (Button) findViewById(R.id.button2);
setpoint.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
textDialog.getWindow().setFlags( 
WindowManager.LayoutParams.FLAG_BLUR_BEHIND, 
WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 
textDialog.getWindow().setLayout(300, 200); 
textDialog.setTitle("Set Temperature"); 

LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View myView = li.inflate(R.layout.main, null); 
textDialog.setContentView(myView); 
textDialog.show(); 
        }
    });
Button set=(Button) findViewById(R.id.button1);
set.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.dummy1);
}
});
}
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
user976538
  • 11
  • 2
  • 3

3 Answers3

3

Assuming you've used the widget right....

NumberPicker numPicker = (NumberPicker)findViewById(R.id.whatever);
int value = numPicker.getValue();
tvTextView.setText(String.valueOf(value));
st0le
  • 33,375
  • 8
  • 89
  • 89
0

pass the value along intetnt using putExtra and by getting it in next class(Activity) you can set that value using setText() method......

Umar Qureshi
  • 5,985
  • 2
  • 30
  • 40
  • where should i use the intent? is it in numberpicker.java class? – user976538 Jan 02 '12 at 10:05
  • As far as i'm getting from your question you have used number picker in one activity and you want to display the value selected by user in next activity. so you must be jumping from the activity where you have used number picker for user to select a value to the activity where you want to display that selection. so for jumping from first activity(where number picker implemented) to 2nd activity (where you have used TextView to display selected value) you must be using intent. – Umar Qureshi Jan 02 '12 at 10:15
  • along this intent use putExtra to pass value and by getting that value in 2nd activity you can set it to TextView using setText() Method. – Umar Qureshi Jan 02 '12 at 10:16
  • For using putExtra you can get help from answer of this question http://stackoverflow.com/questions/5265913/how-to-use-putextra-and-getextra-for-string-data – Umar Qureshi Jan 02 '12 at 10:18
0

The android's numberpicker is a custom view that contains two buttons and a textview. If you can put a complete control on the numberpicker, you can make your own custom numberpicker view, and add a getter method that returns its textbox, or, text of the textbox. you can download the android source code for number picker from here. do not forget to add numberpicker layout xml file from here.

Kayhan Asghari
  • 2,817
  • 1
  • 28
  • 47