久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

android - 在更改 EditText 值時(shí)無(wú)法更新列表視圖

android - cannot update listview on changing an EditText value(android - 在更改 EditText 值時(shí)無(wú)法更新列表視圖)
本文介紹了android - 在更改 EditText 值時(shí)無(wú)法更新列表視圖的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我有一項(xiàng)活動(dòng),它從包含許多國(guó)家/地區(qū)的信息(名稱(chēng)、首都、人口、國(guó)旗圖像)的數(shù)據(jù)庫(kù)中檢索數(shù)據(jù).主布局有一個(gè)以大寫(xiě)名稱(chēng)作為輸入的 EditText 和一個(gè) ListView.啟動(dòng)活動(dòng)時(shí),將檢索所有國(guó)家/地區(qū)并在 ListView 中簡(jiǎn)要顯示.然后在鍵入 EditText 時(shí),我希望 ListView 顯示具有匹配首都名稱(chēng)的國(guó)家/地區(qū).但我看到的是一個(gè)空白的 ListView.此外,如果 EditText 為空,我希望 ListView 顯示開(kāi)頭顯示的所有國(guó)家/地區(qū).

I have an activity that retrieves data from a database that contains information (name, capital, population, flag image) for many countries. The main layout has an EditText to take the capital name as the input and a ListView. On launching the activity, all the countries are retrieved and shown briefly in the ListView. Then on typing in the EditText I want the ListView to show the countries with the matching capital name. But what I see is a blank ListView. Besides if the EditText is empty, I want the ListView to show all the countries as it showed in the beginning.

主要布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_id"
        android:visibility="gone" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/adView"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp" >



        <EditText 
            android:id="@+id/search_input_capital"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:layout_alignParentTop="true"
           android:visibility="visible" >
        <requestFocus />

        </EditText>
        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cacheColorHint="#00000000"
            android:divider="@android:color/transparent"
            android:drawSelectorOnTop="false" 
            android:layout_below="@id/search_input_capital">
        </ListView>
    </RelativeLayout>

</RelativeLayout>

活動(dòng)的代碼(CapitalActivity.java)是:

And the code for the activity ( CapitalActivity.java ) is:

   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_capital);

        private ArrayList<Country> items;
        private ArrayList<Country> items_all;

        private ArrayList<Country>  items_new;

        private EfficientAdapter adapter;
        private ListView listView;


        EditText searchInput=(EditText)findViewById(R.id.search_input_capital);

        items = new ArrayList<Country>();
        items_new = new ArrayList<Country>();
        listView = (ListView) findViewById(R.id.listView);
        listView.setDividerHeight(10);

        adapter = new EfficientAdapter(CapitalActivity.this);
        listView.setAdapter(adapter);

       setListItems("");

      searchInput.addTextChangedListener(new TextWatcher() {

               @Override
               public void afterTextChanged(Editable s) {

               }

               @Override    
               public void beforeTextChanged(CharSequence s, int start,
                 int count, int after) {
               }

               @Override    
               public void onTextChanged(CharSequence s, int start,
                 int before, int count) {


                   String searchCapital = new String(s.toString()).trim();

                 items_new.clear();

               for(Country myCountry  : items_all) {

               if( myCountry.getCapital() != null &&  
                     myCountry.getCapital().trim().toLowerCase().contains(searchCapital)) {

               items_new.add(myCountry);
                 }
                }



             items.clear();

            items = (ArrayList<Country>) items_new.clone();

            if(searchCapital.trim().isEmpty()){

            items = items_all;
            }

            adapter.notifyDataSetChanged();


               }
              });





private void setListItems(String searchKey) {

    items_all= DatabaseAccessor.getCountryList(CapitalActivity.this, type, typeValue, searchKey);
    items=items_all;

    adapter.notifyDataSetChanged();
}

上面只顯示了必要的代碼段.我應(yīng)該怎么做才能達(dá)到目標(biāo)?

Only the necessary code segment has been shown above. What should I do to achieve the target ?

我在上面粘貼的代碼中大部分省略了 EfficientAdapter 實(shí)現(xiàn)部分.但是這次我也粘貼了該代碼:

I mostly omitted the EfficientAdapter implementation part in the code pasted above. However I am pasting that code too this time :

public class EfficientAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        private Context context;

        public EfficientAdapter(Context context) {
            mInflater = LayoutInflater.from(context);
            this.context = context;
        }

        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.country_container, null);
                holder = new ViewHolder();

                holder.nameView = (TextView) convertView.findViewById(R.id.nameView);
                holder.continentView = (TextView) convertView.findViewById(R.id.continentView);
                holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
                holder.detailsView = (TextView) convertView.findViewById(R.id.detailsView);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            OnClickListener ocl = new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(CapitalActivity.this, CountryLearningActivity.class);
                    intent.putExtra(Constants.KEY_COUNTRY, items);
                    intent.putExtra(Constants.KEY_INDEX, position);
                    startActivity(intent);
                }
            };

            Country item = items.get(position);
            holder.nameView.setText(item.getCountry());
            if (type.equalsIgnoreCase(filters[0]) || type.equalsIgnoreCase(filters[1])
                    || type.equalsIgnoreCase(filters[2])) {
                holder.continentView.setText(item.getContinent());
            } else if (type.equalsIgnoreCase(filters[3])) {
                holder.continentView.setText(Html
                        .fromHtml("Area: " + formatter.format(Double.parseDouble(item.getArea())) + " km<sup>2</sup>"));
            } else if (type.equalsIgnoreCase(filters[4])) {
                holder.continentView.setText("Population : " + item.getPopulation());
            }
            holder.imageView.setImageResource(Utils.getResID(CapitalActivity.this, item.getFlag()));
            holder.detailsView.setOnClickListener(ocl);
            convertView.setOnClickListener(ocl);

            return convertView;
        }

        class ViewHolder {
            TextView nameView;
            ImageView imageView;
            TextView continentView;
            TextView detailsView;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public int getCount() {
            return items.size();
        }

        @Override
        public Object getItem(int position) {
            return items.get(position);
        }
    }

推薦答案

只需從當(dāng)前頁(yè)面打開(kāi)同一頁(yè)面即可獲取以下代碼

just open teh same page from your current page for the below code

enter cod  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_capital);

    private ArrayList<Country> items;
    private ArrayList<Country> items_all;

    private ArrayList<Country>  items_new;

    private EfficientAdapter adapter;
    private ListView listView;


    EditText searchInput=(EditText)findViewById(R.id.search_input_capital);

    items = new ArrayList<Country>();
    items_new = new ArrayList<Country>();
    listView = (ListView) findViewById(R.id.listView);
    listView.setDividerHeight(10);

    adapter = new EfficientAdapter(CapitalActivity.this);
    listView.setAdapter(adapter);

   setListItems("");

  searchInput.addTextChangedListener(new TextWatcher() {

           @Override
           public void afterTextChanged(Editable s) {

           }

           @Override    
           public void beforeTextChanged(CharSequence s, int start,
             int count, int after) {
           }

           @Override    
           public void onTextChanged(CharSequence s, int start,
             int before, int count) {


               String searchCapital = new String(s.toString()).trim();

             items_new.clear();

           for(Country myCountry  : items_all) {

           if( myCountry.getCapital() != null &&  
                 myCountry.getCapital().trim().toLowerCase().contains(searchCapital)) {

           items_new.add(myCountry);
             }
            }



         items.clear();

        items = (ArrayList<Country>) items_new.clone();

        if(searchCapital.trim().isEmpty()){

        items = items_all;
        }

        adapter.notifyDataSetChanged();


           }
          });

private void setListItems(String searchKey) {

private void setListItems(String searchKey) {

items_all= DatabaseAccessor.getCountryList(CapitalActivity.this, type, typeValue, searchKey);
items=items_all;

adapter.notifyDataSetChanged();

}這里

這篇關(guān)于android - 在更改 EditText 值時(shí)無(wú)法更新列表視圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 91麻豆精品国产91久久久久久 | 成年人免费在线视频 | 四虎影院免费在线播放 | 国产av毛片| 99免费精品 | 99伊人 | 九九色九九| 激情欧美日韩一区二区 | 亚洲在线看 | 久久综合久久综合久久综合 | 国产99精品 | 国产一区二区在线视频 | 一区二区三区四区电影视频在线观看 | 毛片网在线观看 | 999精品视频在线观看 | 亚洲成人av一区二区 | 午夜视频在线观看一区二区 | 黄色大片观看 | 亚洲精品一区二区三区在线 | 大香在线伊779 | 91精品国产综合久久精品图片 | 亚洲www啪成人一区二区 | 欧美日韩久久久久 | 怡红院成人在线视频 | 在线亚洲人成电影网站色www | 日韩精品| 午夜在线免费观看视频 | 成人日韩 | 亚洲成人精品久久 | 一区二区免费在线观看 | 91在线导航 | 中文成人在线 | 欧美日韩在线一区二区 | 亚洲精品久久久一区二区三区 | 91在线中文字幕 | 天天摸天天干 | 亚洲国产一区二区三区 | 欧美激情在线精品一区二区三区 | 国产精品美女久久久久久不卡 | 视频一区二区三区在线观看 | 97人人澡人人爽91综合色 |