pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Listview android中的Edittext

Edittext in Listview android(Listview android中的Edittext)
本文介紹了Listview android中的Edittext的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有帶有 editext 和 textview 的 Listview.

I have Listview with editext and textview.

當我觸摸 edittext 時,edittext 失去焦點!

When i touch on edittext then edittext lost focus!

我通過設置 android:windowSoftInputMode="adjustPan"(AndroidManifest.xml) 解決了這個問題.現在我觸摸edittext而不是editext獲得焦點,但應用程序標簽和一些原始列表視圖消失(頂部).

I resolved this problem by setting android:windowSoftInputMode="adjustPan"(AndroidManifest.xml). Now i touch on edittext than editext get focus but application label and some raw of listview disappear(top part).

我想在用戶觸摸 edittext 時獲得焦點,而不會丟失應用程序標簽和一些原始列表視圖.

I want to get focus when user touch on edittext without loss application label and some raw of listview.

我已經實現的代碼:

當用戶觸摸edittext但應用程序標簽和一些原始列表視圖在軟鍵盤彈出時消失時,下面的代碼獲得焦點.我想在用戶觸摸edittext時獲得焦點而不丟失應用程序標簽和一些原始列表視圖.

Below coding get focus when user touch on edittext but application label and some raw of listview disappear when soft keypad pop up.I want to get focus when user touch on edittext without loss application label and some raw of listview.

1)AndroidManifest.xml

1)AndroidManifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MyListViewDemoActivity"
                  android:label="@string/app_name"
                  android:windowSoftInputMode="adjustPan"
                  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

</application>

2) raw_layout.xml

2) raw_layout.xml

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <EditText android:id="@+id/mEditText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  />  
</LinearLayout>

3) main.xml

3) main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView android:id="@+id/mListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

4) MyListViewDemoActivity

4) MyListViewDemoActivity

public class MyListViewDemoActivity extends Activity {
    private ListView mListView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mListView=(ListView)findViewById(R.id.mListView);
        mListView.setAdapter(new MyAdapter(this));
    }
}

class MyAdapter extends BaseAdapter {

    private Activity mContext;
    private String character[]={"a","b","c","d","e","f","g","h","i","j"};
    public MyAdapter(Activity context)
    {
        mContext=context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return character.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
private class Holder
{
    EditText mEditText;
}
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final Holder holder;
        if (convertView == null) {
            holder = new Holder();
            LayoutInflater inflater =mContext.getLayoutInflater();
            convertView = inflater.inflate(R.layout.raw_layout, null);
            holder.mEditText = (EditText) convertView
                    .findViewById(R.id.mEditText);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        holder.mEditText.setText(character[position]);
        holder.mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                // TODO Auto-generated method stub
                if (!hasFocus){
                    final EditText etxt = (EditText) v;
                    holder.mEditText.setText(etxt.getText().toString());
                }

            }
        });
        return convertView;
    }

}

推薦答案

我也遇到了同樣的問題.我的數字鍵盤會在被 qwerty 鍵盤替換之前暫時出現,并且 EditText 失去焦點.

I was having the same problem. My numberic keyboard would momentarily appear before being replaced by the qwerty keyboard and the EditText losing focus.

問題是出現的鍵盤使您的 EditText 失去焦點.為防止這種情況發(fā)生,請在您的 AndroidManifest.xml 中為適當的活動(或活動)添加以下內容:

The problem is that the keyboard appearing makes your EditText lose focus. To prevent this put the following in your AndroidManifest.xml for the appropriate Activity (or Activities):

android:windowSoftInputMode="adjustPan"

請參閱 Android 文檔:

See Android documentation:

當輸入法出現在屏幕上時,它會減少可用于應用 UI 的空間量.系統(tǒng)會決定如何調整 UI 的可見部分,但它可能無法正確處理.為確保您的應用獲得最佳行為,您應該指定您希望系統(tǒng)如何在剩余空間中顯示您的 UI.

When the input method appears on the screen, it reduces the amount of space available for your app's UI. The system makes a decision as to how it should adjust the visible portion of your UI, but it might not get it right. To ensure the best behavior for your app, you should specify how you'd like the system to display your UI in the remaining space.

要在活動中聲明您的首選處理方式,請在清單的 <activity> 元素中使用 android:windowSoftInputMode 屬性和adjust"之一.價值觀.

To declare your preferred treatment in an activity, use the android:windowSoftInputMode attribute in your manifest's <activity> element with one of the "adjust" values.

例如,為了確保系統(tǒng)將您的布局調整到可用空間——這確保所有布局內容都可以訪問(即使它可能需要滾動)——使用 adjustResize"

For example, to ensure that the system resizes your layout to the available space—which ensures that all of your layout content is accessible (even though it probably requires scrolling)—use "adjustResize"

這篇關于Listview android中的Edittext的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
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 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 箱式破碎机_移动方箱式破碎机/价格/厂家_【华盛铭重工】 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 | 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 | 球磨机,节能球磨机价格,水泥球磨机厂家,粉煤灰球磨机-吉宏机械制造有限公司 | 三价铬_环保铬_环保电镀_东莞共盈新材料贸易有限公司 | 棉服定制/厂家/公司_棉袄订做/价格/费用-北京圣达信棉服 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 金联宇电缆总代理-金联宇集团-广东金联宇电缆实业有限公司 | 喷漆房_废气处理设备-湖北天地鑫环保设备有限公司 | 非甲烷总烃分析仪|环控百科| 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | 【连江县榕彩涂料有限公司】官方网站 | 厂厂乐-汇聚海量采购信息的B2B微营销平台-厂厂乐官网 | 微水泥_硅藻泥_艺术涂料_艺术漆_艺术漆加盟-青岛泥之韵环保壁材 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 | 壹车网 | 第一时间提供新车_资讯_报价_图片_排行! | 东莞市超赞电子科技有限公司 全系列直插/贴片铝电解电容,电解电容,电容器 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 电抗器-能曼电气-电抗器专业制造商 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂 | 衢州装饰公司|装潢公司|办公楼装修|排屋装修|别墅装修-衢州佳盛装饰 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 杭州代理记账费用-公司注销需要多久-公司变更监事_杭州福道财务管理咨询有限公司 | 山东钢格板|栅格板生产厂家供应商-日照森亿钢格板有限公司 | 奥运星-汽车性能网评-提供个性化汽车资讯 | 抖音短视频运营_企业网站建设_网络推广_全网自媒体营销-东莞市凌天信息科技有限公司 | 浙江皓格药业有限公司| 皮带式输送机械|链板式输送机|不锈钢输送机|网带输送机械设备——青岛鸿儒机械有限公司 | 全球化工设备网—化工设备,化工机械,制药设备,环保设备的专业网络市场。 | 河南中专学校|职高|技校招生-河南中职中专网 | 物流公司电话|附近物流公司电话上门取货 | 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 首页_欧瑞传动官方网站--主营变频器、伺服系统、新能源、软起动器、PLC、HMI | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 小型气象站_车载气象站_便携气象站-山东风途物联网 | 二手电脑回收_二手打印机回收_二手复印机回_硒鼓墨盒回收-广州益美二手电脑回收公司 | 乳化沥青设备_改性沥青设备_沥青加温罐_德州市昊通路桥工程有限公司 |