越来越seekbars的价值和传递价值的意图,以新的活动 [英] getting the values of seekbars and passing values as intents to new activity
本文介绍了越来越seekbars的价值和传递价值的意图,以新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在AndroidTabRestaurantDescFilterListView.java得到NULL值
I am getting NULL values in AndroidTabRestaurantDescFilterListView.java
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 FILTER;
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. */
PRICEbar = (SeekBar)findViewById(R.id.PRICEseekBarID); // make seekbar object
DISTANCEbar = (SeekBar)findViewById(R.id.DISTANCEseekBarID); // make seekbar object
RATINGbar = (SeekBar)findViewById(R.id.RATINGseekBarID); // make seekbar object
FILTER=(Button) findViewById(R.id.TopNavigationBarFilterDoneButton);
rdg = (RadioGroup) findViewById(R.id.radioGroup1);
indian = (RadioButton) findViewById(R.id.IndianRG_ID);
thai = (RadioButton) findViewById(R.id.ThaiRG_ID);
chinese = (RadioButton) findViewById(R.id.ChineseRG_ID);
back=(Button) findViewById(R.id.TopNavigationBarFilterBackButton);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
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);
}
});
////////////////////////////////////////////////////////
DISTANCEbar.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
DISTANCEtextProgress = (TextView)findViewById(R.id.DISTANCEtextViewProgressID);
DISTANCEtextProgress.setText("Distance:: "+progress);
seekBar.setMax(25);
}
});
////////////////////////////////////////////////////////
RATINGbar.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
RATINGtextProgress = (TextView)findViewById(R.id.RATINGtextViewProgressID);
RATINGtextProgress.setText("Rating:: "+progress);
seekBar.setMax(5);
RatingBar ratingBar = (RatingBar)findViewById(R.id.RATINGfinalvalueratingID);
ratingBar.setRating(5);
ratingBar.setFocusable(false);
RatingBar ratingBar1 = (RatingBar)findViewById(R.id.RATINGinitialvalueratingID);
ratingBar1.setRating(0);
ratingBar.setFocusable(false);
}
});
rdg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if(i==R.id.BreakfastRG_ID){
selectedType = indian.getText().toString();
}else if(i==R.id.LunchRG_ID){
selectedType = thai.getText().toString();
}else{
selectedType = chinese.getText().toString();
}
}
});
FILTER.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent FilterIntent=new Intent(Filters.this,AndroidTabRestaurantDescFilterListView.class);
FilterIntent.putExtra("REST1",selectedType);
FilterIntent.putExtra("PriceBar", PRICEbar.getProgress());
FilterIntent.putExtra("DistanceBar", DISTANCEbar.getProgress());
FilterIntent.putExtra("RatingBar", RATINGbar.getProgress());
startActivity(FilterIntent);
}
});
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (seekBar == PRICEbar)
PRICEtextProgress.setText("Price:: Rs "+progress);
else if (seekBar == DISTANCEbar)
DISTANCEtextProgress.setText("Distance:: "+progress);
else if (seekBar == RATINGbar)
RATINGtextProgress.setText("Rating:: "+progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
AndroidTabRestaurantDescFilterListView.java
public class AndroidTabRestaurantDescFilterListView extends TabActivity {
// TabSpec Names
private static final String INBOX_SPEC = "Rating";
private static final String OUTBOX_SPEC = "Price";
private static final String PROFILE_SPEC = "Distance";
Button Photos;
Button Filter;
Button Search;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Photos=(Button) findViewById(R.id.PhotoButton);
Filter=(Button) findViewById(R.id.FilterButton);
Search=(Button) findViewById(R.id.SearchBottomBarID);
TabHost tabHost = getTabHost();
String REST1 = getIntent().getStringExtra("REST1");
String PriceBar = getIntent().getStringExtra("PriceBar");
String DistanceBar = getIntent().getStringExtra("DistanceBar");
String RatingBar = getIntent().getStringExtra("RatingBar");
// Tab
TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
Intent inboxIntent = new Intent(this, RatingDescriptionFilterActivity.class);
inboxIntent.putExtra("REST1", REST1);
inboxIntent.putExtra("PriceBar", PriceBar);
inboxIntent.putExtra("DistanceBar", DistanceBar);
inboxIntent.putExtra("RatingBar", RatingBar);
inboxSpec.setIndicator(INBOX_SPEC);
inboxSpec.setContent(inboxIntent);
// Tab
TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
Intent PriceIntent = new Intent(this, PriceDescriptionFilterActivity.class);
PriceIntent.putExtra("REST1", REST1);
PriceIntent.putExtra("PriceBar", PriceBar);
PriceIntent.putExtra("DistanceBar", DistanceBar);
PriceIntent.putExtra("RatingBar", RatingBar);
PriceSpec .setIndicator(OUTBOX_SPEC);
PriceSpec.setContent(PriceIntent);
// Tab
TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
Intent DistanceIntent = new Intent(this, DistanceDescriptionFilterActivity.class);
DistanceIntent.putExtra("REST1", REST1);
DistanceIntent.putExtra("PriceBar", PriceBar);
DistanceIntent.putExtra("DistanceBar", DistanceBar);
DistanceIntent.putExtra("RatingBar", RatingBar);
DistanceSpec .setIndicator(PROFILE_SPEC);
DistanceSpec.setContent(DistanceIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec);
tabHost.addTab(PriceSpec);
tabHost.addTab(DistanceSpec);
//Set the current value tab to default first tab
tabHost.setCurrentTab(0);
//Setting custom height for the tabs
final int height = 45;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;
Photos.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent PhotoIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,AndroidTabRestaurantDescImageListView.class);
startActivity(PhotoIntent);
}
});
Filter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent FilterIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,Filters.class);
startActivity(FilterIntent);
}
});
Search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent FilterIntent=new Intent(AndroidTabRestaurantDescFilterListView.this,SearchPage.class);
startActivity(FilterIntent);
}
});
}
}
LOG
10-21 19:53:11.376: E/AndroidRuntime(1393): FATAL EXCEPTION: AsyncTask #2
10-21 19:53:11.376: E/AndroidRuntime(1393): java.lang.RuntimeException: An error occured while executing doInBackground()
10-21 19:53:11.376: E/AndroidRuntime(1393): at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.lang.Thread.run(Thread.java:1096)
10-21 19:53:11.376: E/AndroidRuntime(1393): Caused by: java.lang.NullPointerException
10-21 19:53:11.376: E/AndroidRuntime(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.doInBackground(RatingDescriptionFilterActivity.java:86)
10-21 19:53:11.376: E/AndroidRuntime(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.doInBackground(RatingDescriptionFilterActivity.java:1)
10-21 19:53:11.376: E/AndroidRuntime(1393): at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-21 19:53:11.376: E/AndroidRuntime(1393): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-21 19:53:11.376: E/AndroidRuntime(1393): ... 4 more
10-21 19:53:15.026: E/WindowManager(1393): Activity com.project.findmybuffet.AndroidTabRestaurantDescFilterListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45fb1c10 that was originally added here
10-21 19:53:15.026: E/WindowManager(1393): android.view.WindowLeaked: Activity com.project.findmybuffet.AndroidTabRestaurantDescFilterListView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45fb1c10 that was originally added here
10-21 19:53:15.026: E/WindowManager(1393): at android.view.ViewRoot.<init>(ViewRoot.java:247)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-21 19:53:15.026: E/WindowManager(1393): at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.Dialog.show(Dialog.java:241)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity$DownloadJSON.onPreExecute(RatingDescriptionFilterActivity.java:77)
10-21 19:53:15.026: E/WindowManager(1393): at android.os.AsyncTask.execute(AsyncTask.java:391)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.RatingDescriptionFilterActivity.onCreate(RatingDescriptionFilterActivity.java:60)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-21 19:53:15.026: E/WindowManager(1393): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
10-21 19:53:15.026: E/WindowManager(1393): at android.widget.TabHost.addTab(TabHost.java:213)
10-21 19:53:15.026: E/WindowManager(1393): at com.project.findmybuffet.AndroidTabRestaurantDescFilterListView.onCreate(AndroidTabRestaurantDescFilterListView.java:87)
我的分析::
- 我能够从seekbars获取值
PRICEbar
,DISTANCEbar
,的RatingBar
- 我传递从
filter.java
来意图AndroidTabRestaurantDescFilterListView.java
....所有这三个来自seekbars获得整数 - 但是我得到的NULL值
AndroidTabRestaurantDescFilterListView.java
上课的时候我收到
它们作为下一个活动的意图 - I am able to get the values from the seekbars
PRICEbar
,DISTANCEbar
,RATINGbar
- I am passing as intents from
filter.java
toAndroidTabRestaurantDescFilterListView.java
.... All three are integers obtained from seekbars - But i am getting NULL values in
AndroidTabRestaurantDescFilterListView.java
class when i recieve them as intents in next activity
My Analysis::
调试结果:: ** **为AndroidTabRestaurantDescFilterListView
this AndroidTabRestaurantDescFilterListView (id=830102681688)
tabHost TabHost (id=830102691544)
savedInstanceState null
REST1 "Chinese" (id=830102732832)
PriceBar null
DistanceBar null
-
为什么会出现在这里NULL?
Why am i getting NULL here ?
我如何调试呢?
推荐答案
seekbar.getProgress()
返回一个int值。public synchronized int getProgress () Added in API level 1 Get the progress bar's current level of progress. Return 0 when the progress bar is in indeterminate mode. Returns the current progress, between 0 and getMax()
所以,当检索值使用
So when retrieving values use
int PriceBar = getIntent().getIntExtra("PriceBar",0); int DistanceBar = getIntent().getIntExtra("DistanceBar",0); int RatingBar = getIntent().getIntExtra("RatingBar",0);
getIntExtra
public int getIntExtra (String name, int defaultValue) Added in API level 1 Retrieve extended data from the intent. Parameters name The name of the desired item. defaultValue the value to be returned if no value of the desired type is stored with the given name. Returns the value of an item that previously added with putExtra() or the default value if none was found.
这篇关于越来越seekbars的价值和传递价值的意图,以新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文