gpt4 book ai didi

android - Edittext 无法在 android 中加载时隐藏键盘

转载 作者:行者123 更新时间:2023-11-29 15:39:20 27 4
gpt4 key购买 nike

我在 oncreate() 方法中有用于搜索的 edittext,但每当我默认启动 Activity 时,edittext 都有 RequestFocus() 意味着它会打开键盘启动 Activity 。我想隐藏那个键盘。以下是我的代码:

public class TwoList extends AppCompatActivity {
private final String TAG = this.getClass().getName();
TextView tablenoset, orderidset;
String OrderIdFromService, Kotidfromservice, item, str, wId, tid, tabletype, newmenuname, fromservertable, serverorderid, response, forcheck, newmenuoflist, uname, tabletid, converttostringtbid, comtid;
int myvalue, convertedorderid, convertednewtid, convertedorderidforlist, quantityoflist, rateforlist, totalamountoflist, midforlist, tab_id;
ListView leftList;
String cntforb;
ListView rightList;
ArrayAdapter<String> adapter;
Context context;

ArrayList<String> data;
ArrayAdapter<String> adapter1;
ArrayList<String> data1;
Button GetOrder, place_orderbutton;
private DbHelper mHelper;
private SQLiteDatabase dataBase;
private DataForTempNew mydatabase;
private DatabaseForOrderlist databaseforrate;
private DataBaseHandlerForMenu menudatafor;
AlertDialog.Builder alertDialog;
EditText searchmenu,searchCategory;
int _id;

int value;
String convertedvalue;
HashMap<Integer, Integer> hasmap = new HashMap<Integer, Integer>();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.row);
Toolbar toolbar = (Toolbar) findViewById(R.id.product_toolBar_title);
setSupportActionBar(toolbar);
//place_orderbutton=(Button)findViewById(R.id.button_6);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(TwoList.this, MainActivity.class);
i.putExtra("Uname", uname);
i.putExtra("ForButton", cntforb);
startActivity(i);
}
});


cntforb = TwoList.this.getIntent().getExtras().getString("ForButton");
uname = TwoList.this.getIntent().getExtras().getString("User_name");
//tab_id = TwoList.this.getIntent().getExtras().getInt("Tabid");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
tabletid = prefs.getString("tabid", "no id");
searchCategory=(EditText)findViewById(R.id.inputSearchcategory);

alertDialog = new AlertDialog.Builder(TwoList.this);

GetOrder = (Button) findViewById(R.id.button_5);
str = TwoList.this.getIntent().getExtras().getString("Mystring");
wId = TwoList.this.getIntent().getExtras().getString("WaiteriD");
tid = TwoList.this.getIntent().getExtras().getString("Tid");
serverorderid = TwoList.this.getIntent().getExtras().getString("OrderIdnew");
response = TwoList.this.getIntent().getExtras().getString("Yes");
forcheck = TwoList.this.getIntent().getExtras().getString("No");
menudatafor = new DataBaseHandlerForMenu(this);
data = new ArrayList<String>();
data1 = new ArrayList<String>();
databaseforrate = new DatabaseForOrderlist(this);
mydatabase = new DataForTempNew(this);
mHelper = new DbHelper(this);

//OrderIdFromService = String.valueOf(tab_id);
new AsyncLoadOrderId().execute();
try {
myvalue = Integer.parseInt(str);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
//myvalue = Integer.parseInt(str);
ForGettingRate insertformenurate = new ForGettingRate(str);
new AsyncMenuRate().execute(insertformenurate);
GetOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(TwoList.this, DisplayActivity.class);
intent.putExtra("Tableno", str);
intent.putExtra("OrderIds", OrderIdFromService);
intent.putExtra("WaiterIDs", wId);
intent.putExtra("Tabletype", tabletype);
intent.putExtra("user_name", uname);
intent.putExtra("ForButton", cntforb);
intent.putExtra("KOTid", Kotidfromservice);
startActivity(intent);

}
});
if (forcheck != null && forcheck.equals("Yes")) {
GetOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent intentifyes = new Intent(TwoList.this, DisplayActivity.class);
intentifyes.putExtra("Tableno", str);
intentifyes.putExtra("OrderIds", fromservertable);
intentifyes.putExtra("WaiterIDs", wId);
intentifyes.putExtra("Tabletype", tabletype);
intentifyes.putExtra("KOTid", Kotidfromservice);
intentifyes.putExtra("user_name", uname);
intentifyes.putExtra("ForButton", cntforb);
intentifyes.putExtra("Response", "Yes");
startActivity(intentifyes);

}
});

}
tablenoset = (TextView) findViewById(R.id.tableno_ofneworder);
orderidset = (TextView) findViewById(R.id.tableorder_id);
leftList = (ListView) findViewById(R.id.lstLeft);
/* Typeface custom_font = Typeface.createFromAsset(getAssets(), "Fonts/DroidSerif-Regular.ttf");
leftli.setTypeface(custom_font);*/
//tablenoset.setText(str);
getTableno();
context = this;

searchCategory.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
TwoList.this.adapter.getFilter().filter(s);

}

@Override
public void afterTextChanged(Editable s) {
}
});
leftList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedFromList = (leftList.getItemAtPosition(position).toString());

InsertCategoryFrom insertfromhere = new InsertCategoryFrom(selectedFromList);
new AsyncCreateCategory().execute(insertfromhere);
LayoutInflater inflater = getLayoutInflater();
View convertView = (View) inflater.inflate(R.layout.nnsample, null);
alertDialog.setTitle("Menu");
rightList = (ListView) convertView.findViewById(R.id.lstRight);
searchmenu = (EditText) convertView.findViewById(R.id.inputSearch);
searchmenu.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
TwoList.this.adapter1.getFilter().filter(s);
}

@Override
public void afterTextChanged(Editable s) {
}
});
populateRightList();
//alertDialog.setView(searchmenu);
alertDialog.setView(convertView);
adapter1.clear();
adapter1.notifyDataSetChanged();
alertDialog.show();


}
});
alertDialog.setPositiveButton("Back", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog alert = alertDialog.create();
alert.dismiss();
}
});


populateLeftList();


}
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}

最佳答案

你需要设置android:windowSoftInputMode="stateHidden" in manifests.xml

或者试试

android:windowSoftInputMode="adjustPan"

您也可以引用以下链接:

https://developer.android.com/training/keyboard-input/visibility.html#ShowOnStart

关于android - Edittext 无法在 android 中加载时隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43695985/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com