0
我是新来的Java和Android开发人员,我无法修复错误。我想用变量更改TextView
的文本,但视图类是静态的。下面的代码:无法对非静态方法进行静态引用 - Android TabbedActivity
public static class FirstTab extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.first_tab, null);
new Thread() {
public void run() {
MCQuery mcQuery = new MCQuery(serverAddress, 25565);
QueryResponse response = mcQuery.basicStat();
int Onlineplayers = response.getOnlinePlayers();
Log.d("MCQuery", "" + Onlineplayers + " Online Players");
}
}.start();
TextView onlinePlayersView = (TextView) findViewById(R.id.online_players);
onlinePlayersView.setText(Onlineplayers);
return v;
}
}
的错误是:“不能让从活动类型的静态引用非静态方法findViewById(int)
”
我怎样才能解决这个问题?
尝试使用v.findViewById(),看看是否有帮助... – Shark 2012-07-30 17:11:02