用于在 Android 中移动其他列表项的列表视图中的编辑文本的键盘

发布于 2024-10-11 19:13:18 字数 7895 浏览 1 评论 0 原文

我有一个列表视图,所有列表项都有不同的布局。我的第一个列表项包含一个编辑文本。每当我点击它时,键盘就会出现。但是这个键盘会替换列表视图中的所有列表项。每当我单击该编辑文本时,这些项目就会更改其位置。我对此真的很困惑。

这是我的代码:

 public View getView(int position, View convertView, ViewGroup parent) {

         ViewHolder holder;
         if (convertView == null) {
             if(position == 0)
             {
                 convertView = mInflater.inflate(R.layout.remindertitle, null); 
                 edttxtForTitle = (EditText) convertView.findViewById(R.id.edittext);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 1)
             {
                 convertView = mInflater.inflate(R.layout.reminderfrom, null);    
                 TextView txtTitle = (TextView) convertView.findViewById(R.id.txtvwFrom);
                 txtTitle.setText("From");
                 mPickDate = (Button) convertView.findViewById(R.id.btnDate);
                 mPickDate.setText(
                            new StringBuilder()
                                    // Month is 0 based so add 1
                                    .append(mDays[mDay].substring(0, 3)).append(", ")
                                    .append(mDay).append(" ")
                                    .append(mMonths[mMonth]).append(" ")
                                    .append(mYear).append(" "));
                 mPickDate.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = true;
                            showDialog(DATE_DIALOG_ID);
                        }
                    });

                 strDateFrom = new StringBuilder()
                 // Month is 0 based so add 1
                .append(mDays[mDay].substring(0, 3)).append(", ")
                .append(mDay).append(" ")
                 .append(mMonths[mMonth]).append(" ")
                 .append(mYear).append(" ");

                 mPickTime = (Button) convertView.findViewById(R.id.btnTime);
                 mPickTime.setText(
                         new StringBuilder()
                            .append(pad(mHour)).append(":")
                            .append(pad(mMinute)));
                 mPickTime.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = true;
                            showDialog(TIME_DIALOG_ID);
                        }
                    });
                 strTimeFrom = new StringBuilder()
                .append(pad(mHour)).append(":")
                .append(pad(mMinute));
             }

             else if(position == 2)
             {
                 convertView = mInflater.inflate(R.layout.reminderto, null);    
                 TextView txtTitle = (TextView) convertView.findViewById(R.id.txtvwTo);
                 txtTitle.setText("To");
                 mPickDateForFinalDate = (Button) convertView.findViewById(R.id.btnDatefinal);
                 mPickDateForFinalDate.setText(
                            new StringBuilder()
                                    // Month is 0 based so add 1
                                    .append(mDays[mfinalDay].substring(0, 3)).append(", ")
                                    .append(mfinalDay).append(" ")
                                    .append(mMonths[mfinalMonth]).append(" ")
                                    .append(mfinalYear).append(" "));
                 mPickDateForFinalDate.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = false;
                            showDialog(DATE_DIALOG_ID_FINAL);
                        }
                    });

                 strDateFrom = new StringBuilder()
                 // Month is 0 based so add 1
                .append(mDays[mfinalDay].substring(0, 3)).append(", ")
                .append(mfinalDay).append(" ")
                 .append(mMonths[mfinalMonth]).append(" ")
                 .append(mfinalYear).append(" ");

                 mPickTimeForFinalTime = (Button) convertView.findViewById(R.id.btnTimefinal);
                 mPickTimeForFinalTime.setText(
                         new StringBuilder()
                            .append(pad(mfinalHour)).append(":")
                            .append(pad(mfinalMinute)));
                 mPickTimeForFinalTime.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = false;
                            showDialog(TIME_DIALOG_ID_FINAL);
                        }
                    });
                 strTimeFrom = new StringBuilder()
                .append(pad(mfinalHour)).append(":")
                .append(pad(mfinalMinute));
                 }

             else if(position == 3)
             {
                 convertView = mInflater.inflate(R.layout.allday, null);   

                 convertView.setMinimumHeight(60);
             }

             else if(position == 4)
             {
                 convertView = mInflater.inflate(R.layout.alarm, null);
                 txtAlarm = (TextView) convertView.findViewById(R.id.txtAlarmValue);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 5)
             {
                 convertView = mInflater.inflate(R.layout.repeat_view, null);  
                 txtRepeat = (TextView)convertView.findViewById(R.id.txtRepeatValue);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 6)
             {
                 convertView = mInflater.inflate(R.layout.submitbutton_view, null);  
                 Button btnSubmit = (Button)convertView.findViewById(R.id.btnSubmit);
                 btnSubmit.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String title = edttxtForTitle.getText().toString();

                            Log.v("","all the values title" + title);
                            Log.v("","all the values datefrom" + strDateFrom.toString());
                            Log.v("","all the values dateto" + strDateTo.toString());
                            Log.v("","all the values timefrom" + strTimeFrom.toString());
                            Log.v("","all the values timeto" + strTimeTo.toString());
                            Log.v("","all the values allday" + allDay);
                            Log.v("","all the values alarm" + strAlarm);
                            Log.v("","all the values repeat" + strRepeat);

                        }
                    });
                 convertView.setMinimumHeight(60);
             }

             holder = new ViewHolder();      
             holder.btnFromDate = (Button) convertView.findViewById(R.id.btnDate);
             holder.btnFromTime = (Button) convertView.findViewById(R.id.btnTime);
             holder.txtLabelTitle = (TextView) convertView.findViewById(R.id.txtvwFrom);
             holder.btnFromDatefinal = (Button) convertView.findViewById(R.id.btnDatefinal);
             holder.btnFromTimefinal = (Button) convertView.findViewById(R.id.btnTimefinal);
             holder.txtLabelTitlefinal = (TextView) convertView.findViewById(R.id.txtvwTo);

             convertView.setTag(holder);    

         } else {
             holder = (ViewHolder) convertView.getTag();
         }

         return convertView;
     }

      class ViewHolder {
         Button btnFromDate; 
         Button btnFromTime; 
         TextView txtLabelTitle;
         Button btnFromDatefinal; 
         Button btnFromTimefinal; 
         TextView txtLabelTitlefinal;
       }

我是在搞乱 LayoutInflator 吗?

I have a listview with different layouts for all the listitems. My first listitem contains an edittext. Whenever I click on this, keyboard shows up. But this keyboard displaces all the listitems in the listview. Whenever I click that edittext, the items change their positions. I'm really confused about this.

This is my code:

 public View getView(int position, View convertView, ViewGroup parent) {

         ViewHolder holder;
         if (convertView == null) {
             if(position == 0)
             {
                 convertView = mInflater.inflate(R.layout.remindertitle, null); 
                 edttxtForTitle = (EditText) convertView.findViewById(R.id.edittext);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 1)
             {
                 convertView = mInflater.inflate(R.layout.reminderfrom, null);    
                 TextView txtTitle = (TextView) convertView.findViewById(R.id.txtvwFrom);
                 txtTitle.setText("From");
                 mPickDate = (Button) convertView.findViewById(R.id.btnDate);
                 mPickDate.setText(
                            new StringBuilder()
                                    // Month is 0 based so add 1
                                    .append(mDays[mDay].substring(0, 3)).append(", ")
                                    .append(mDay).append(" ")
                                    .append(mMonths[mMonth]).append(" ")
                                    .append(mYear).append(" "));
                 mPickDate.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = true;
                            showDialog(DATE_DIALOG_ID);
                        }
                    });

                 strDateFrom = new StringBuilder()
                 // Month is 0 based so add 1
                .append(mDays[mDay].substring(0, 3)).append(", ")
                .append(mDay).append(" ")
                 .append(mMonths[mMonth]).append(" ")
                 .append(mYear).append(" ");

                 mPickTime = (Button) convertView.findViewById(R.id.btnTime);
                 mPickTime.setText(
                         new StringBuilder()
                            .append(pad(mHour)).append(":")
                            .append(pad(mMinute)));
                 mPickTime.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = true;
                            showDialog(TIME_DIALOG_ID);
                        }
                    });
                 strTimeFrom = new StringBuilder()
                .append(pad(mHour)).append(":")
                .append(pad(mMinute));
             }

             else if(position == 2)
             {
                 convertView = mInflater.inflate(R.layout.reminderto, null);    
                 TextView txtTitle = (TextView) convertView.findViewById(R.id.txtvwTo);
                 txtTitle.setText("To");
                 mPickDateForFinalDate = (Button) convertView.findViewById(R.id.btnDatefinal);
                 mPickDateForFinalDate.setText(
                            new StringBuilder()
                                    // Month is 0 based so add 1
                                    .append(mDays[mfinalDay].substring(0, 3)).append(", ")
                                    .append(mfinalDay).append(" ")
                                    .append(mMonths[mfinalMonth]).append(" ")
                                    .append(mfinalYear).append(" "));
                 mPickDateForFinalDate.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = false;
                            showDialog(DATE_DIALOG_ID_FINAL);
                        }
                    });

                 strDateFrom = new StringBuilder()
                 // Month is 0 based so add 1
                .append(mDays[mfinalDay].substring(0, 3)).append(", ")
                .append(mfinalDay).append(" ")
                 .append(mMonths[mfinalMonth]).append(" ")
                 .append(mfinalYear).append(" ");

                 mPickTimeForFinalTime = (Button) convertView.findViewById(R.id.btnTimefinal);
                 mPickTimeForFinalTime.setText(
                         new StringBuilder()
                            .append(pad(mfinalHour)).append(":")
                            .append(pad(mfinalMinute)));
                 mPickTimeForFinalTime.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            settingValueForFromOrTo = false;
                            showDialog(TIME_DIALOG_ID_FINAL);
                        }
                    });
                 strTimeFrom = new StringBuilder()
                .append(pad(mfinalHour)).append(":")
                .append(pad(mfinalMinute));
                 }

             else if(position == 3)
             {
                 convertView = mInflater.inflate(R.layout.allday, null);   

                 convertView.setMinimumHeight(60);
             }

             else if(position == 4)
             {
                 convertView = mInflater.inflate(R.layout.alarm, null);
                 txtAlarm = (TextView) convertView.findViewById(R.id.txtAlarmValue);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 5)
             {
                 convertView = mInflater.inflate(R.layout.repeat_view, null);  
                 txtRepeat = (TextView)convertView.findViewById(R.id.txtRepeatValue);
                 convertView.setMinimumHeight(60);
             }

             else if(position == 6)
             {
                 convertView = mInflater.inflate(R.layout.submitbutton_view, null);  
                 Button btnSubmit = (Button)convertView.findViewById(R.id.btnSubmit);
                 btnSubmit.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String title = edttxtForTitle.getText().toString();

                            Log.v("","all the values title" + title);
                            Log.v("","all the values datefrom" + strDateFrom.toString());
                            Log.v("","all the values dateto" + strDateTo.toString());
                            Log.v("","all the values timefrom" + strTimeFrom.toString());
                            Log.v("","all the values timeto" + strTimeTo.toString());
                            Log.v("","all the values allday" + allDay);
                            Log.v("","all the values alarm" + strAlarm);
                            Log.v("","all the values repeat" + strRepeat);

                        }
                    });
                 convertView.setMinimumHeight(60);
             }

             holder = new ViewHolder();      
             holder.btnFromDate = (Button) convertView.findViewById(R.id.btnDate);
             holder.btnFromTime = (Button) convertView.findViewById(R.id.btnTime);
             holder.txtLabelTitle = (TextView) convertView.findViewById(R.id.txtvwFrom);
             holder.btnFromDatefinal = (Button) convertView.findViewById(R.id.btnDatefinal);
             holder.btnFromTimefinal = (Button) convertView.findViewById(R.id.btnTimefinal);
             holder.txtLabelTitlefinal = (TextView) convertView.findViewById(R.id.txtvwTo);

             convertView.setTag(holder);    

         } else {
             holder = (ViewHolder) convertView.getTag();
         }

         return convertView;
     }

      class ViewHolder {
         Button btnFromDate; 
         Button btnFromTime; 
         TextView txtLabelTitle;
         Button btnFromDatefinal; 
         Button btnFromTimefinal; 
         TextView txtLabelTitlefinal;
       }

Am I messing around with LayoutInflator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2024-10-18 19:13:18

您可以使用此代码来实现此目的。

您必须在代码下面添加 android.manifest.xml 文件:

android:windowSoftInputMode="adjustPan"

为了您的目的,您还可以在那里设置其他属性。

You can use this code for that.

You have to add android.manifest.xml file below code:

android:windowSoftInputMode="adjustPan"

For your purpose you can also set other properties there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文