0

problem with settingText for each and individual edittext in listview.Edittext focus missing.enter image description here.Check my image above which is haveing custom keypad and i need to settext when keypad buttons is pressed.Below is my code. i tried but the focus is going for some other edittext.Please help me out.

private LayoutInflater mInflater;
   public ArrayList myItems = new ArrayList();
   List < HashMap < String, String >> painItems;
public MyAdapet()
{
     mInflater = (LayoutInflater)  getSystemService(Context.LAYOUT_INFLATER_SERVICE);
painItems = new ArrayList < HashMap < String, String >> ();
     HashMap < String, String > map = new HashMap < String, String > ();
for(int i=1;i<10;i++)
{

map.put("row_2", "Location Content");
map.put("row_3","Content");
map.put("row_4", "50");
map.put("row_5", "");
painItems.add(map);
}



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

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

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

     if (convertView == null) {
         convertView = mInflater.inflate(R.layout.custom_xml, null);

     } else {

     }
     returnText = (EditText) convertView
             .findViewById(R.id.returnedit);
     returnText.setInputType(InputType.TYPE_NULL);
     //Fill EditText with the value you have in <span id="r774jm31_1" class="r774jm31">data source</span>


     //we need to update adapter once we finish with editing
     returnText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

             listview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
                returnText.requestFocus();

        }
    });

    return convertView;
}

My Listxml:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp" >

      <ListView
                        android:id="@+id/listView1"
                        android:layout_width="match_parent"
                         android:descendantFocusability="afterDescendants"
android:focusable="false"
                        android:layout_height="wrap_content" >
                    </ListView>
                </LinearLayout>

My custom List:

   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout 
         android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#cfcfcf"
        android:gravity="center">
    <RelativeLayout 
     android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      >
      <ImageView 
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/seq_bg"
         android:layout_centerInParent="true"


  />
<TextView
    android:id="@+id/sqlno"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_centerInParent="true"
    android:gravity="left"
    android:text="1"
    android:textColor="#000000"
    android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
    android:textStyle="bold" />

</RelativeLayout>
    <TextView
         android:id="@+id/lcontent"
       android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left"
        android:text="Location"
        android:textColor="#ffffff"
              android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
        android:textStyle="bold" />

      <TextView
             android:id="@+id/addcontent"
       android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:gravity="left"
          android:text="Add Content"
          android:textColor="#ffffff"
                 android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
          android:textStyle="bold" />

       <TextView 
              android:id="@+id/drop"
      android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="50"
    android:textColor="#ffffff"
         android:gravity="center"
    android:textStyle="bold"
         android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
    android:layout_weight="1"
        />
        <EditText 
              android:id="@+id/returnedit"
         android:layout_width="0dp"
    android:layout_height="wrap_content"
         android:gravity="center"
    android:text="67"
    android:textColor="#000000"
    android:textStyle="bold"

           android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"

    android:layout_weight="1"
        />
        <Button 
             android:id="@+id/viewnotesButton"
         android:layout_width="0dp"
    android:layout_height="wrap_content"
         android:gravity="center"
    android:text="view Notes"
    android:textColor="#000000"
    android:textStyle="bold"
           android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"

    android:layout_weight="1"

            />
</LinearLayout>
</LinearLayout>

My clicklisteners for custom kepad is like this:

button0.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                returnText.setText(returnText.getText().toString()+"0");
                 MyAdapet.notifyDataSetChanged();
            }
        });
        button1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                returnText.setText(returnText.getText().toString()+"1");
                 MyAdapet.notifyDataSetChanged();
            }
        });
AVINASH KANNA
  • 617
  • 1
  • 5
  • 11

1 Answers1

0

try this code -

 returnText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

             listview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
                returnText.requestFocus();
                  notifyDataSetChanged(); // for update adapter


        }
    });

Hope this code helps you !!! if its not working please let me know i will try to help more.

shweta_jain
  • 453
  • 1
  • 5
  • 19