I have a custom listview that has 3 editTexts inside it along with a button.
By defualt, I don't want the editTexts to be editable so I set
android:focusable="true"
But then at some point I want that button when clicked should make them editable
So inside getView(I am using a custom adapter) I set an onClick listener as:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Log.d("Reached: ","Getview");
ViewHolder viewHolder = null;
if (convertView == null) {
LayoutInflater inflator = LayoutInflater.from(getContext());
convertView = inflator.inflate(R.layout.list_view, null);
viewHolder = new ViewHolder();
viewHolder.product_nameET= (EditText) convertView.findViewById(R.id.product_nameET);
viewHolder.priceET= (EditText) convertView.findViewById(R.id.priceET);
viewHolder.quantity_availableET= (EditText) convertView.findViewById(R.id.quantity_availableET);
viewHolder.edit_button= (Button) convertView.findViewById(R.id.edit_rowButton);
//viewHolder.product_nameET.setFocusable(true);
final ViewHolder vh=viewHolder;
viewHolder.edit_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//lv.getChildAt(position).setFocusable(true);
vh.product_nameET.setFocusable(true);//////This line here has no effect
}
});
convertView.setTag(viewHolder);
convertView.setTag(R.id.product_nameET, viewHolder.product_nameET);
convertView.setTag(R.id.priceET, viewHolder.priceET);
convertView.setTag(R.id.quantity_availableET, viewHolder.quantity_availableET);
convertView.setTag(R.id.edit_rowButton, viewHolder.edit_button);
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.product_nameET.setText(product_namesList.get(position));
viewHolder.priceET.setText(priceList.get(position));
viewHolder.quantity_availableET.setText(quantity_availableList.get(position));
return convertView;
}
But this has no effect whatsoever. Please help I am new to android.
Try to set below two properties with true(enable)/false(disable) value based on conditions :
For Enable EditText For Input:
vh.product_nameET.setFocusable(true);
vh.product_nameET.setFocusableInTouchMode(true);
For Disable EditText For Input:
vh.product_nameET.setFocusable(false);
vh.product_nameET.setFocusableInTouchMode(false);