このアダプタクラスでは、ボタンクリック時にユーザーが入力したEditText値を読み込もうとしています。 EditTextとボタンの両方がListView項目の中にあります。その価値を読み取る最良の方法は何ですか?私が下に試した方法は、EditTextフィールドから正しい値を取得しませんでした。ボタンをクリックすると、ListViewアイテム内の編集済みのEditTextフィールド値をどのように読み取ることができますか?
@Override
public View getView(final int position, View convertView, final ViewGroup parent)
{
box = null;
db = new database(getContext());
if (convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(layout, null);
box = new container();
box.X = (TextView) convertView.findViewById(R.id.manage_X);
box.Y = (TextView) convertView.findViewById(R.id.manage_Y);
box.Z = (TextView) convertView.findViewById(R.id.manage_Z);
box.button = (Button) convertView.findViewById(R.id.manage_button);
convertView.setTag(box);
}
else
{
box = (container) convertView.getTag();
}
box.X.setText(getItem(position).getX());
box.Y.setText(String.valueOf(getItem(position).getY()));
box.button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
View view = View.inflate(getContext(), R.layout.activity_manage, null);
string_is = (EditText) view.findViewById(R.id.manage_Z);
value_is = new Integer(string_is.getText().toString());
// In my ListView, I have an item with 1 EditText and a button.
// User can enter a value for Z, which is EditText.
// I want to read that value upon button click and do things with it.
// My above method does not capture the correct Z value.
});
return convertView;
}
public class container
{
TextView X;
TextView Y;
TextView Z;
Button button;
}
共有スクリーンショット... –
View view = View.inflate(getContext()、R.layout.activity_manage、null);なぜアダプタのレイアウトを膨らませるのですか? –