在android中使用简单的搜索栏

时间:2013-10-21 05:31:29

标签: android seekbar

如何从SeekBar获取值并将它们作为意图传递给另一个活动


我有三个搜索栏,如下所示

  • PRICEbar
  • DISTANCEbar
  • 的RatingBar

  1. 我希望从三个搜索栏中获取所选值,并通过DoneIntent
  2. 将其作为意图传递给另一项活动
  3. 如何实现这一目标

  4. Filters.java

    public class Filters extends Activity implements OnSeekBarChangeListener{
    
        // declare text objects variables
        private SeekBar PRICEbar,DISTANCEbar, RATINGbar; 
        private TextView PRICEtextProgress,DISTANCEtextProgress, RATINGtextProgress;
    
        Button back;
        Button Done;
    
    
        private RadioGroup rdg;
        private RadioButton indian;
        private RadioButton thai;
        private RadioButton chinese;
    
    
        private String selectedType="";
    
    
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            // load the layout
            setContentView(R.layout.filters);   
    
    
            /** Finding all the views in this Activity. */
            back=(Button) findViewById(R.id.TopNavigationBarFilterBackButton);
    
    
    
    
            Done=(Button) findViewById(R.id.SEARCH_BUTTON_ID);
            Done.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    Intent DoneIntent=new Intent(Filters.this,AndroidTabRestaurantDescFilterListView.class);
    
                    DoneIntent.putExtra("REST1",selectedType);
                    startActivity(DoneIntent);
                }
            });
    
    
    
            PRICEbar = (SeekBar)findViewById(R.id.PRICEseekBarID); // make seekbar object
            PRICEbar.setOnSeekBarChangeListener(this); 
            PRICEbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    // TODO Auto-generated method stub
                    PRICEtextProgress = (TextView)findViewById(R.id.PRICEtextViewProgressID);
                    PRICEtextProgress.setText("Price:: Rs "+progress);
                    seekBar.setMax(100);
    
                }
            });
    
    
    
    
    }
    

1 个答案:

答案 0 :(得分:2)

使用PRICEbar.getProgress();获取搜索栏的当前值。然后使用以下代码将它们作为意图传递:

Intent intent = new Intent(MainActivity.this, YourNewActivity.class);
intent.PutExtra("PriceBar", PRICEbar.getProgress());
intent.PutExtra("DistanceBar", DISTANCEbar.getProgress());
intent.PutExtra("RatingBar", RATINGbar.getProgress());
startActivity(intent);