0

问题:在 Listview 中交换 EditText 内的文本。它发生在键盘不可见或可见时。如下图所示。

图 1:当键盘可见时

图 2:当键盘不可见时

图 3:当键盘可见时

代码:ListView 活动类:

    public class DayPlannerFormActivity extends Activity {

    private TextView txtHeader;
    private Context mContext;
    private ListView lvDayplannerFrom;
    private FormDayPlannerAdapter adapter;
    private Activity activity;
    final Handler mHandler = new Handler();

    private Vector<DayPlannerForm> list = new Vector<DayPlannerForm>();
    final Runnable mUpdateResults = new Runnable() {
        public void run() {
            updateResultsInUi();
        }
    };

   @Override
   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dayplanner);
        mContext = this;    
        activity = this;
        txtHeader = (TextView) findViewById(R.id.txtHeader);
        txtHeader.setText(R.string.haivlate);
        lvDayplannerFrom = (ListView) findViewById(R.id.lvDayplanner);
        startfetchOperation();

   }

    private void updateResultsInUi() {
        adapter= new FormDayPlannerAdapter(activity,list);
        lvDayplannerFrom.setAdapter(adapter);

    }

    protected void startfetchOperation() {
        Thread t = new Thread() {
                @Override
                public void run() {
                    getData();
                }
            };
            t.start();
        }

   private void getData() {
    try{
         list.clear();
         DayPlannerForm dpf = new  DayPlannerForm("Task Name 1","","");
         list.add(dpf);
         dpf =new  DayPlannerForm("Task Name 2","","");
         list.add(dpf);
         mHandler.post(mUpdateResults);
       } catch (Exception e){
                mHandler.post(mUpdateResults);
       }
  }
  @Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
     try{

         if(lvDayplannerFrom != null)
             lvDayplannerFrom.setAdapter(null);

     } catch (Exception e){}
} 
}

代码:列表视图适配器类

public class FormDayPlannerAdapter extends BaseAdapter {

    private Activity mActivity;
    private static Vector<DayPlannerForm> list;
    private static LayoutInflater inflater;
    private Context mContext;
    public FormDayPlannerAdapter ( Activity _activity,Vector<DayPlannerForm> _list) {
        mActivity = _activity;
        mContext = _activity;
        list = _list;
        inflater = (LayoutInflater)mActivity.getSystemService(mActivity.LAYOUT_INFLATER_SERVICE);
    }

    public static class ViewHolder{
        public TextView txtTaskName;
        public CheckBox chbAction;
        public EditText edtDecription;
    }


    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }


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


    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

         View vi=convertView;
            ViewHolder holder;
            if(convertView==null){
                vi = inflater.inflate(R.layout.dayplanner_listitem_form, null);
                holder=new ViewHolder();
                holder.txtTaskName=(TextView)vi.findViewById(R.id.txtTaskName);
                holder.chbAction = (CheckBox) vi.findViewById(R.id.chbAction);
                holder.edtDecription =  (EditText) vi.findViewById(R.id.edtDecription);
                vi.setTag(holder);
            }
            else
              holder=(ViewHolder)vi.getTag();

            holder.txtTaskName.setText(list.get(position).getTaskName());


        return vi;
    }

}

如何解决这个问题

4

2 回答 2

1

问题解决再见在 manifest.xml 的活动标签中添加 android:windowSoftInputMode="adjustPan" 这个属性

于 2012-01-25T12:58:36.240 回答
0

乍一看,我认为以下代码会出现问题:-

DayPlannerForm dpf = new  DayPlannerForm("Task Name 1","","");
         list.add(dpf);
         dpf =new  DayPlannerForm("Task Name 2","","");
         list.add(dpf); 

您应该为每个Task Name采用不同的 DayPlannerForm 类对象。

DayPlannerForm dpf1,dpf2; 
      dpf1 = new  DayPlannerForm("Task Name 1","","");
      list.add(dpf1);
      dpf2 =new  DayPlannerForm("Task Name 2","","");
      list.add(dpf2); 

我认为这可能会解决您的问题。

于 2012-01-24T06:14:20.987 回答