如果我更改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>