-1

If i Change in EditText field android:focusable=false, then clickable is proper working but i cant able to modify the EditText values. But if i change focusable=true, clickable is not working but i can change the EditText values. Our requirement is enable to modifying the EditText values and clickable in the list.

Thanks in advance.

    public class TicketActivity extends Activity{
TextView t1;
TextView t2;
ListView l1;
TextView t6;
   public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket);
t1=(TextView)findViewById(R.id.textView3);
t2=(TextView)findViewById(R.id.textView5);
l1=(ListView)findViewById(R.id.listView1);

   //Get the Table no Value From Edit Text


  Intent i1=getIntent();
Bundle b=i1.getExtras();
int num=b.getInt("Table No:");
    String pno=Integer.toString(num);
    t1.setText(pno);

        //Get The Guest Value From Edit Text

    Intent i2=getIntent();
    Bundle b1=i2.getExtras();
    int num1=b1.getInt("Guest:");
    String pno1=Integer.toString(num1);
    t2.setText(pno1);


  // List<String> st=GlobalClass.myval;

   //ArrayAdapter<String> ada = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1,st);

   l1.setAdapter(new EfficientAdapter(TicketActivity.this));

   l1.setOnItemClickListener(new OnItemClickListener(){
   public void onItemClick(AdapterView<?> parent,View view,int position,long id){

  Toast.makeText(getApplicationContext(), "Selected:",Toast.LENGTH_SHORT).show();

    }
     });


       // l1.setOnFocusChangeListener(new OnFocusChangeListener() {
     //  public void onFocusChange(View v, boolean hasFocus) {
   //       int index= (int) ((ListView)v).getSelectedItemId();   Log.i("index",""+index);

 //   }
//});
     } 
         private static class EfficientAdapter extends BaseAdapter{
    private LayoutInflater mInflater;



    public EfficientAdapter(Context context){
        mInflater=LayoutInflater.from(context);

    // implementation of EfficientAdapter   
    }
    public int getCount() {

        return GlobalClass.myval.size();//<GlobalClass.myvals.size()?GlobalClass.myval.size():GlobalClass.myvals.size();

    }
    public Object getItem(int position) {

        return position;
    }
    public long getItemId(int position) {

        return position ;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        String[] stockArr = new String[GlobalClass.myval.size()];
        stockArr = GlobalClass.myval.toArray(stockArr);
        String[] stockArr1=new String[GlobalClass.myvals.size()];
        stockArr1=GlobalClass.myvals.toArray(stockArr1);
    if(convertView==null){
            convertView=mInflater.inflate(R.layout.list_ticket, null);

            holder=new ViewHolder();
            holder.Text1=(EditText) convertView.findViewById(R.id.editText1);
            holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
            holder.Text3=(TextView) convertView.findViewById(R.id.textView3);

            convertView.setTag(holder);
        }
        else{
              holder=(ViewHolder)convertView.getTag();
            }
           holder.Text1.setText("1");
            holder.Text2.setText(stockArr[position]);
            holder.Text3.setText(stockArr1[position]);
            return convertView;

     }

    }
    static class ViewHolder{
        EditText Text1;
        TextView Text2;
        TextView Text3;

    }

   }

list_ticket.xml:

      <?xml version="1.0" encoding="UTF-8"?>
       <LinearLayout 
     android:orientation="horizontal"
     android:layout_height="match_parent"
     android:layout_width="match_parent"
     xmlns:android="http://schemas.android.com/apk/res/android">
     <EditText
    android:id="@+id/editText1"
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:inputType="number" 
    android:ems="10"
    android:focusable="false"
    android:focusableInTouchMode="true">


    </EditText>

  <TextView
      android:layout_height="wrap_content"
      android:layout_width="130dp" 
      android:id="@+id/textView2" 
      android:gravity="right"/>

    <TextView 
      android:layout_height="wrap_content"
      android:layout_width="70dp"
      android:id="@+id/textView3" 
      android:gravity="right"/> 
     </LinearLayout>
USER5762
  • 277
  • 5
  • 14
  • 1
    http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/ – Lalit Poptani Aug 09 '12 at 09:08
  • If i Change in editText field android:focusable=false, then clickable is proper working but i cant able to modify the edittext values,you cant type in it when `android:focusable=false` found you didnt googled http://stackoverflow.com/questions/2679948/focusable-edittext-inside-listview/4901683#4901683 :) – J.K Aug 09 '12 at 09:09
  • ok check this also http://www.lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html – Lalit Poptani Aug 10 '12 at 12:48

1 Answers1

0

I think what you have got is a situation where your EditText field is overriding the row selection. If you post the code for what you have it will give a better idea of where the problem is.

Does your EditText fill the row? If it does then this field is the one being clicked not the row. Try making the EditText field smaller and then you should be able to click outside the EditText field, this will confirm this is your problem.

UPDATE When you click the EditText field the device assumes you want to edit this text. When you click on the other text fields does you click get fired? Do you really need an EditText field in a list item?

Phil H
  • 897
  • 4
  • 10
  • S I NEED BCOS edittext field is a quantity section so i need to modify the qty.another text views are items and price so dont change . – USER5762 Aug 10 '12 at 13:33
  • and what happens if you click on one of the price or qty fields. Does you row item click listener get fired? – Phil H Aug 10 '12 at 13:38
  • if i set in xml android:focusable=true then not fired the list row to onclick.but edit text only focused to edit.if i set false then the list row got fired and edit text cant able to edit. – USER5762 Aug 10 '12 at 13:44
  • if i set in xml android:focusable=true then not fired the list row to onclick.but edit text only focused to edit.if i set false then the list row got fired and edit text cant able to edit – USER5762 Aug 10 '12 at 14:04
  • and what happens if you set the click listener on each of the textView items. Do this in the adapter and see if that works for you. Comment out the l1.setOnItemClickListener. – Phil H Aug 10 '12 at 14:09
  • IF I SET THEN EDIT TEXT IS NOT FOCUSED AND NOT EDITABLE. – USER5762 Aug 10 '12 at 14:21
  • have you tried what I said? comment out the onItemClickListener in the activity, add a onClickListener to @+id/textView2 and @+id/textView3. Then the click will be fired if either of those fields is clicked. You can set different click listeners for different elements in each row, i.e. edittext does one thing and the other two textViews do something else. Just not very intuitive for the user. – Phil H Aug 10 '12 at 16:22