有时候直接发起一个程序,发起后本身关闭
public class WrapperActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-1212"));
startActivity(intent);
finish(); //这才是关键的}
}
我用上面的就可以了,这样按返回键不会出现上面的活动,有的人说加上
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 而不是finish 没有是结果如何
cb=(CheckBox)findViewById(R.id.cek);
cb.setOnClickListener(new OnClickListener() { // checkbox listener
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
tv1.setVisibility(0); //visible==0
et3.setVisibility(0);
} else if (((CheckBox) v).isChecked() == false) {
tv1.setVisibility(2); //gone=2
et3.setVisibility(2);
}
}
});
这里不能使用数字 直接使用gone等不然没有效果,
2.
class AddTask extends AsyncTask<Void, Item, Void> {
protected void onPreExecute() {
// pDialog = ProgressDialog.show(MyActivity.this,"Please wait...", "Retrieving data ...", true);
dialog = new ProgressDialog(viewContacts.this);
dialog.setMessage(getString(R.string.please_wait_while_loading));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
protected Void doInBackground(Void... unused) {
items = parser.getItems();
for (Item it : items) {
publishProgress(it);
}
return(null);
}
protected void onProgressUpdate(Item... item) {
adapter.add(item[0]);
}
protected void onPostExecute(Void unused) {
pDialog.dismiss();
}
}
今天想到一个问题如果我选了listView中的一个item 的位置然后启动另一个activity回来的时候在返回那个位置
@Override
protected void onPause()
{
// Save scroll position
SharedPreferences preferences = context.getSharedPreferences("SCROLL", 0);
SharedPreferences.Editor editor = preferences.edit();
int scroll = mListView.getScrollY();
editor.put("ScrollValue", scroll);
editor.commit();
}
@Override
protected void onResume()
{
// Get the scroll position
SharedPreferences preferences = context.getSharedPreferences("SCROLL", 0);
int scroll = preferences.getInt("ScrollView", 0);
mListView.scrollTo(0, scroll);
}
竟然忘记使用SharedPreference了