我创建了一个ListView
,并且TextView
中有ListView
。
身份TextView
为value_text
。我使用viewHolder.value_text
获取TextView
,如下面的代码。
public View getView(final int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder viewHolder;
Log.d(TAG, "getView");
if(view == null){
view = mInflator.inflate(R.layout.streamid_data, null);
viewHolder = new ViewHolder();
viewHolder.value_text = (TextView) view.findViewById(R.id.Value_text);
viewHolder.value_text.setText("1");
}else {
viewHolder = (ViewHolder) view.getTag();
}
return view;
}
我想使用thread
并更改text
的{{1}}。但似乎无法获得viewHolder.value_text
中的value_text
。
thread
位于runnable
之外。
getView method
如何在final Runnable setList = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//change the text of value_text
}
};
之外获取TextView
; ?
答案 0 :(得分:0)
使ViewHolder变量全局化。然后你可以在Thread中访问textview。
// Global in Adapter Class
ViewHolder accessable_ViewHolder;
public View getView(final int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d(TAG, "getView");
if(view == null){
view = mInflator.inflate(R.layout.streamid_data, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.value_text = (TextView) view.findViewById(R.id.Value_text);
viewHolder.value_text.setText("1");
}else {
accessable_ViewHolder= (ViewHolder) view.getTag();
}
return view;
}
// Thread
final Runnable setList = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//change the text of value_text
accessable_ViewHolder.value_text.setText("Value set from Thread");
}
};