我是android新手,我想問一些問題,我搜索了幾個線程,但找不到具體的解決方案。Android:通過屬於ListView的按鈕更新ListView中的多個EditTexts
我想提出一個ListView看起來像這樣:
http://postimg.org/image/9ib8gjq95/
///////////////////////// /////////////////////////////////////
// // TextView的//的EditText鍵+ //按鈕 - //
//////////////////////////////////////// ////////////////
這ListView的是動態盟友用相同模式的新行更新(TextView,EditText,Button +,Button-)。
我想單擊一行的+/-按鈕並更改此行中EditText中存在的編號。
package com.example.test2; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class EditCAdapter extends ArrayAdapter<Prosthesi> { int counter=0; Context context; String onoma; int layoutResourceId; ArrayList<Prosthesi> data = new ArrayList<Prosthesi>(); public EditCAdapter(Context context, int layoutResourceId, ArrayList<Prosthesi> data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(final int position, View convertView, ViewGroup parent) { View row3 = convertView; UserHolder holder = null; if (row3 == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); row3 = inflater.inflate(layoutResourceId, parent, false); holder = new UserHolder(); holder.kodikos=(TextView)row3.findViewById(R.id.textD); holder.plus = (Button) row3.findViewById(R.id.buttD); holder.minus=(Button) row3.findViewById(R.id.buttD2); holder.posotita=(EditText)row3.findViewById(R.id.e4); row3.setTag(holder); } else { holder = (UserHolder) row3.getTag(); } Prosthesi user = data.get(position); holder.kodikos.setText(user.getName()); holder.plus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub counter++; //do the stuff I described //tried this but it isn't working! // UserHolder holder=(UserHolder)v.getTag(); // holder.posotita.setText(String.valueOf(counter)); } }); return row3; } static class UserHolder { TextView kodikos; EditText posotita; Button plus; Button minus; } }
日Thnx提前!!!!
嘿你有什麼答案嗎?如果是的話請告訴我 –