Android Programming Tutorials

(Romina) #1
Sitting in the Background

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);

name=(EditText)findViewById(R.id.name);
address=(EditText)findViewById(R.id.addr);
notes=(EditText)findViewById(R.id.notes);
types=(RadioGroup)findViewById(R.id.types);

Button save=(Button)findViewById(R.id.save);

save.setOnClickListener(onSave);

ListView list=(ListView)findViewById(R.id.restaurants);

adapter=new RestaurantAdapter();
list.setAdapter(adapter);

TabHost.TabSpec spec=getTabHost().newTabSpec("tag1");

spec.setContent(R.id.restaurants);
spec.setIndicator("List", getResources()
.getDrawable(R.drawable.list));
getTabHost().addTab(spec);

spec=getTabHost().newTabSpec("tag2");
spec.setContent(R.id.details);
spec.setIndicator("Details", getResources()
.getDrawable(R.drawable.restaurant));
getTabHost().addTab(spec);

getTabHost().setCurrentTab( 0 );

list.setOnItemClickListener(onListClick);
}

Also, add another data member, an int named progress.


Step #2: Create the Work Method......................................................


The theory of this demo is that we have something that takes a long time,


and we want to have that work done in a background thread and update


the progress along the way. So, the first step is to build something that will


run a long time.


70
Free download pdf