[英]listview scrolls to bottom of screen
我有一個具有以下布局的活動。
因此,在此屏幕中, ListView
最初為空。 我在EditText
鍵入一些文本,然后單擊它旁邊的搜索圖標,該應用程序從服務器獲取了項目並填充了ListView
。 現在的問題是ListView
向下滾動到最后一項。
我的搜索Button
onClick()
的代碼
String str_searchTxt = mEt_search.getText().toString().trim();
if (str_searchTxt.length() == 0) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.ENTER_MANDATORY),
Toast.LENGTH_LONG).show();
return;
}
// get items List in araryList
itemList = getItemList(messageHandler,str_searchTxt);
我的消息處理程序中的代碼:
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 2:
String txt = msg.getData().getString("text");
Log.i("Result", txt);
progressDialog.dismiss();
if (txt.equalsIgnoreCase("success")) {
lview3 = (ListView) findViewById(R.id.listView1);
adapter = new ListViewCustomAdapter(
SearchAssetActivity.this, itemList);
lview3.setAdapter(adapter);
lview3.setOnItemClickListener(SearchAssetActivity.this);
lview3.requestFocus();
lview3.setSelection(0);
}
}
您可以使用ListView的setSelection(position) ,
mListView.setSelection(first_position);
否則您可以嘗試,
mListView.setSelectionAfterHeaderView();
嘗試這個:
yourscrollview.fullScroll(ScrollView.FOCUS_UP);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.