EDITTEXT在列表视图的android视图、列表、EDITTEXT、android

2023-09-13 23:51:32 作者:霓裳.

我有列表视图与editext和TextView的。

当我触摸的EditText那么的EditText失去焦点!

我通过设置解决了这个问题安卓windowSoftInputMode =adjustPan(AndroidManifest.xml中)。 现在,我触摸的EditText比editext获得焦点,但应用标签和ListView的部分原料消失(顶部)。

我想获得关注,当用户在触摸的EditText不损失应用标签和ListView的一些生。

code,我已经实现了:

下面的编码获得焦点的时候,当软键盘弹出up.I希望得到重点的EditText,但应用程序标签,用户触摸和ListView的部分原料消失,当EditText上没有损失的应用标签和ListView的一些原始用户的触摸。

1)AndroidManifest.xml中

 <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
        <活动机器人:MyListViewDemoActivityNAME =
                  机器人:标签=@字符串/ APP_NAME
                  机器人:windowSoftInputMode =adjustPan
                  >
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;

< /用途>
 

2)raw_layout.xml

 <的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:方向=垂直
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT>
  < EditText上机器人:ID =@ + ID / mEditText
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT
  />
< / LinearLayout中>
 
Android手机端有哪些是目录树视图的文件管理器 就是图上那样,图上的是X plore,目前我唯

3)的main.xml

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
< ListView的机器人:ID =@ + ID / mListView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
/>
< / LinearLayout中>
 

4)MyListViewDemoActivity

 公共类MyListViewDemoActivity延伸活动{
    私人的ListView mListView;
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        mListView =(ListView控件)findViewById(R.id.mListView);
        mListView.setAdapter(新MyAdapter(本));
    }
}

类MyAdapter扩展了BaseAdapter {

    私人活动mContext;
    私人字符串字符[] = {一个,B,C,D,E,F,G,H,I,J};
    公共MyAdapter(活动范围内)
    {
        mContext =背景;
    }

    @覆盖
    公众诠释getCount将(){
        // TODO自动生成方法存根
        返回character.length;
    }

    @覆盖
    公共对象的getItem(INT位置){
        // TODO自动生成方法存根
        返回null;
    }

    @覆盖
    众长getItemId(INT位置){
        // TODO自动生成方法存根
        返回0;
    }
私有类持有人
{
    的EditText mEditText;
}
    @覆盖
    公共查看getView(INT位置,查看convertView,ViewGroup中父){
        // TODO自动生成方法存根
        最终持有人;
        如果(convertView == NULL){
            持有人=新的持有人();
            LayoutInflater充气= mContext.getLayoutInflater();
            convertView = inflater.inflate(R.layout.raw_layout,NULL);
            holder.mEditText =(EditText上)convertView
                    .findViewById(R.id.mEditText);
            convertView.setTag(保持器);
        } 其他 {
            支架=(座)convertView.getTag();
        }
        holder.mEditText.setText(字[位置]);
        holder.mEditText.setOnFocusChangeListener(新OnFocusChangeListener(){

            @覆盖
            公共无效onFocusChange(视图V,布尔hasFocus){
                // TODO自动生成方法存根
                如果(!hasFocus){
                    最后的EditText etxt =(EditText上)V;
                    holder.mEditText.setText(etxt.getText()的toString());
                }

            }
        });
        返回convertView;
    }

}
 

解决方案

没有看到你的code,我们怎么能提出有关问题的可能解决方案。因此,保持尽可能张贴code,每当你问任何问题的做法。

不过,这里我发现了一个教程实施的 Android的可调焦的EditText里面的ListView 。通过这个例子,并尝试实现自己的方式,或找出你的问题的解决方案。

I have Listview with editext and textview.

When i touch on edittext then edittext lost focus!

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).

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

Code that i have implemented :

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

<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

<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

<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

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;
    }

}

解决方案

Without seeing your code, how can we suggest the possible solution for your problem. So keep practice of posting possible code whenever you ask any question.

However, here i have found one tutorial for implementing Android Focusable EditText inside ListView. Go through the example and try to implement in your way or find out the solution for your problem.