如何使findViewById在Andorid的Fragment内的线程内工作? [重复]

问题描述 投票:1回答:1
我在使用findViewById的片段中包含此线程,但是我不能将getView()或View的变量放在它前面来解决该问题(我确实解决了大多数此类错误代码)。以下代码中的findViewById是无法解析的代码。我该如何解决?

public class SpeedFragment extends Fragment { View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_speed, container, false); new Thread() { public void run() { try { sleep(1500); } catch (Throwable t) { } try { BitmapFactory.Options options = new BitmapFactory.Options(); final ImageView v = findViewById(R.id.testBackground);

java android android-fragments findviewbyid
1个回答
1
投票
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_speed, container, false); ImageView v = view.findViewById(R.id.testBackground); // Add your code// return view; }
© www.soinside.com 2019 - 2024. All rights reserved.