我打算从一个页面更改为另一个页面,因此第一个屏幕上有标题栏和导航栏,我想更改为另一个页面,只有 textview 没有标题栏,当我不在 fucos 到我的 edittext 时。
这是代码:
public class MainActivity extends Activity{
private EditText edittext;
private ListView list;
private CustomListAdapter customAdapter;
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// this.tv = (TextView) this.findViewById(R.id.textView1);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
//new ConnnectionRequest(tv,"95","3025");
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
drawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_launcher, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle("Rodolfo");
edittext.setText("");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("Navalon");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
drawerLayout.setDrawerListener(drawerToggle);
addKeyListener();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
public void addKeyListener() {
List<String> arrayStrings = new ArrayList<String>();
arrayStrings.add("rodolfo");
arrayStrings.add("erodolfo2");
edittext = (EditText) findViewById(R.id.editText);
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
//Remove title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.second_screen);
}
}
});
list = (ListView) findViewById(R.id.list_view);
customAdapter = new CustomListAdapter(this,R.layout.list_item,R.id.product_name,arrayStrings);
list.setAdapter(customAdapter);
edittext.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable arg0) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
MainActivity.this.customAdapter.getFilter().filter(cs);
}
});
}
}
在我的 edditext 被初始化的 addkeyListener 方法中,我的 edditext 也在 setOnFucos 更改中,在我更改到页面的地方发生了错误。我不知道为什么它给我一个错误。
10-03 20:47:47.916: E/AndroidRuntime(9023): FATAL EXCEPTION: main
10-03 20:47:47.916: E/AndroidRuntime(9023): **android.util.AndroidRuntimeException: requestFeature() must be called before adding content**
10-03 20:47:47.916: E/AndroidRuntime(9023): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:268)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.app.Activity.requestWindowFeature(Activity.java:3310)
10-03 20:47:47.916: E/AndroidRuntime(9023): at com.example.octranspodestination.MainActivity$2.onFocusChange(MainActivity.java:122)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.onFocusChanged(View.java:4571)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.widget.TextView.onFocusChanged(TextView.java:7640)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.widget.EditText.onFocusChanged(EditText.java:172)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.clearFocus(View.java:4461)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.ViewGroup.clearFocus(ViewGroup.java:775)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.setFlags(View.java:8518)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.setVisibility(View.java:5631)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.support.v4.widget.DrawerLayout$ViewDragCallback.onViewPositionChanged(DrawerLayout.java:1364)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.support.v4.widget.ViewDragHelper.continueSettling(ViewDragHelper.java:730)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.support.v4.widget.DrawerLayout.computeScroll(DrawerLayout.java:764)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.getDisplayList(View.java:12594)
10-03 20:47:47.916: E/AndroidRuntime(9023): at android.view.View.getDisplayList(View.java:12650)