-1

如果我更改EditText字段android:focusable=false,则clickable工作正常,但我无法修改EditText值。但如果我改变focusable=true,可点击不起作用,但我可以改变EditText值。我们的要求是能够修改EditText列表中的值和可点击。

提前致谢。

    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>
4

1 回答 1

0

我认为您所遇到的是您的 EditText 字段覆盖行选择的情况。如果您发布您所拥有的代码,它将更好地了解问题所在。

你的 EditText 填满了行吗?如果是这样,则该字段是被单击的字段,而不是该行。尝试使 EditText 字段更小,然后您应该能够在 EditText 字段之外单击,这将确认这是您的问题。

更新 当您单击 EditText 字段时,设备假定您要编辑此文本。当您单击其他文本字段时,您单击会被解雇吗?你真的需要一个列表项中的 EditText 字段吗?

于 2012-08-09T09:03:17.740 回答