我有一個自定義的listview,裏面有3個editTexts和一個按鈕。如何在listview中設置可聚焦的成員元素?
通過defualt,我不希望editTexts可編輯,所以我設置
android:focusable="true"
但總有那麼我想這個按鈕點擊應該讓他們可編輯的
所以裏面getView(我使用的是自定義適配器)我設置一個onClick監聽器:
@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;
}
但這並沒有任何作用。請幫助我是Android新手。
你有沒有嘗試一起使用setFocusable和setFocusableInTouchMode? –
@HareshChhelana這工作 – TheGuy
偉大的我有帖子回答請檢查並接受和upvote,如果它是解決你的問題,所以它會幫助其他同樣。 –