【发布时间】:2019-05-25 08:49:47
【问题描述】:
我已经阅读了android.app.Application cannot be cast to android.app.Activity,但我没有解决我的问题。我试着写代码
totalebevuto = (TextView) this.findViewById(R.id.totalebevuto);
按照帖子中的建议,但出现错误。
public class MyReceiver2 extends BroadcastReceiver {
WordListOpenHelper mDB;
WordListAdapter mAdapter;
TextView totalebevuto;
@Override
public void onReceive(Context context, Intent intent) {
mDB = new WordListOpenHelper(context);
// AGGIUNGERE LA DATA AL DATABASE
totalebevuto = (TextView) ((Activity)context).findViewById(R.id.totalebevuto);
mDB.insert_daily(Integer.parseInt(totalebevuto.getText().toString()));
mDB.clear();
mAdapter = new WordListAdapter(context, mDB);
mAdapter.notifyDataSetChanged();
Toast.makeText(context, "OnReceive2", Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
-
显示你的完整代码
-
你到底想做什么?
-
我把所有的代码都贴出来了
标签: android