问题描述
我有一个TextView,EDITTEXT一个自定义的ListView和上一排按钮。 ListView控件与适配器创建的。结果
我想更新与EDITTEXT输入的值TextView的时候我preSS的按钮。
我想这样做,而无需刷新整个列表。结果
任何IDEEA我怎样才能从列表中只更新一行?结果
谢谢!
要更清楚,我会提供code:
私有静态类EfficientAdapter延伸BaseAdapter {
私人LayoutInflater mInflater;
上下文myContext;
公共EfficientAdapter(上下文的背景下){
mInflater = LayoutInflater.from(上下文);
myContext =背景;
} 公众诠释的getCount(){
返回nameList.length;
} 公共对象的getItem(INT位置){
返回的位置;
} 众长getItemId(INT位置){
返回的位置;
} 公共查看getView(最终诠释的立场,观点convertView,
父母的ViewGroup){
最后ViewHolder持有人;
如果(convertView == NULL){
convertView = mInflater.inflate(R.layout.travelpassengers_item,
空值);
持有人=新ViewHolder();
holder.ratingTv =(TextView中)convertView
.findViewById(R.id.tvTPRating); holder.rateBtn =(按钮)convertView
.findViewById(R.id.btnTPRate);
holder.plusBtn =(按钮)convertView
.findViewById(R.id.btnPlus);
holder.minusBtn =(按钮)convertView
.findViewById(R.id.btnMinus);
holder.rateEt =(EditText上)convertView
.findViewById(R.id.etTPRating);
}其他{
支架=(ViewHolder)convertView.getTag();
} holder.ratingTv.setText(等级[位置] +/ 10); holder.callBtn.setTag(PHONELIST [位置]); holder.ratingBtn.setTag(IDS [位置]);
holder.ratingDisableBtn.setTag(numberRates [位置]);
holder.ratingTv.setTag(等级[位置]);
holder.rateEt.setTag(位置); holder.rateBtn.setOnClickListener(新View.OnClickListener(){ 公共无效的onClick(视图v){
// TODO自动生成方法存根
。字符串ID = holder.ratingBtn.getTag()的toString();
INT位置=的Integer.parseInt(holder.rateEt
。.getTag()的toString());
双oldRate =双
.parseDouble(等级[位置]);
INT数= numberRates [位置]
双newRate = Double.parseDouble(holder.rateEt
。.getText()的toString()); DecimalFormat的oneDigit =新的DecimalFormat(
#,## 0.0);
数++;
双平均=(oldRate + newRate)/号码;
newRate = Double.valueOf(oneDigit.format(AVG));
//我想把从newRate值在合适的位置上holder.ratingTv而不更新整个ListView控件。 }
}
}); holder.plusBtn.setOnClickListener(新View.OnClickListener(){ 公共无效的onClick(视图v){
// TODO自动生成方法存根
INT率=的Integer.parseInt(holder.rateEt.getText()
的ToString());
如果(速度小于10){
率++;
holder.rateEt.setText(Integer.toString(率));
}
}
}); holder.minusBtn.setOnClickListener(新View.OnClickListener(){ 公共无效的onClick(视图v){
// TODO自动生成方法存根
INT率=的Integer.parseInt(holder.rateEt.getText()
的ToString());
如果(速度大于0){
率 - ;
holder.rateEt.setText(Integer.toString(率));
}
}
}); 返回convertView;
} 静态类ViewHolder {
公众的TextView ratingTv;
公共按钮minusBtn,plusBtn;
公众的EditText rateEt;
公共按钮rateBtn;
}
}
TextView的电视=(TextView中)getViewById(R.id.myTextView);
等的EditText =(EditText上)getViewById(R.id.myEditText);
按钮B =(按钮)getViewById(R.id.myButton);
b.setOnClickListener(新OnClickListener(){
公共无效的onClick(视图v){
tv.setText(et.getText());
}
});
这可能需要一些调整,因为我还没有测试出来(如为CharSequence为String铸)。
I have a custom listView with a textView, editText and a Button on a row. The listView is created with an adapter.
I want to update the textView with the value entered in editText when I press the button.I want to do this without refreshing the entire list.
Any ideea how can I update only one row from the list?
Thanks!
To be more clear I'll provide the code:
private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; Context myContext;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
myContext = context;
}
public int getCount() {
return nameList.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.travelpassengers_item,
null);
holder = new ViewHolder();
holder.ratingTv = (TextView) convertView
.findViewById(R.id.tvTPRating);
holder.rateBtn = (Button) convertView
.findViewById(R.id.btnTPRate);
holder.plusBtn = (Button) convertView
.findViewById(R.id.btnPlus);
holder.minusBtn = (Button) convertView
.findViewById(R.id.btnMinus);
holder.rateEt = (EditText) convertView
.findViewById(R.id.etTPRating);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ratingTv.setText(rating[position] + "/10");
holder.callBtn.setTag(phoneList[position]);
holder.ratingBtn.setTag(ids[position]);
holder.ratingDisableBtn.setTag(numberRates[position]);
holder.ratingTv.setTag(rating[position]);
holder.rateEt.setTag(position);
holder.rateBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String id = holder.ratingBtn.getTag().toString();
int position = Integer.parseInt(holder.rateEt
.getTag().toString());
double oldRate = Double
.parseDouble(rating[position]);
int number = numberRates[position];
double newRate = Double.parseDouble(holder.rateEt
.getText().toString());
DecimalFormat oneDigit = new DecimalFormat(
"#,##0.0");
number++;
double avg = (oldRate + newRate) / number;
newRate = Double.valueOf(oneDigit.format(avg));
// I want to put the value from newRate in the holder.ratingTv on right position without updating entire listView.
}
}
});
holder.plusBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
int rate = Integer.parseInt(holder.rateEt.getText()
.toString());
if (rate < 10) {
rate++;
holder.rateEt.setText(Integer.toString(rate));
}
}
});
holder.minusBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
int rate = Integer.parseInt(holder.rateEt.getText()
.toString());
if (rate > 0) {
rate--;
holder.rateEt.setText(Integer.toString(rate));
}
}
});
return convertView;
}
static class ViewHolder {
public TextView ratingTv;
public Button minusBtn, plusBtn;
public EditText rateEt;
public Button rateBtn;
}
}
TextView tv = (TextView) getViewById(R.id.myTextView);
EditText et = (EditText) getViewById(R.id.myEditText);
Button b = (Button) getViewById(R.id.myButton);
b.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
tv.setText(et.getText());
}
});
This may require some tweaking, as I haven't tested it out (such as a cast from CharSequence to String).
这篇关于从项目在自定义的ListView的Android更新的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!