条形图活动卡在looper中(android.os)

4jb9z9bj  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(196)

我的arraylist对象可以从barchart\u journal\u活动解析到我的片段中,但是每次我单击选项菜单中的项目时,barchart\u journal\u活动中没有显示任何内容,当我调试它时,它会卡在一个循环中(looper.java)。我该怎么解决这个问题?
我试图解析列表的片段中的代码(它可以工作):

@Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.option1:
                ArrayList<JournalNote> journalList = new ArrayList();
                for(JournalNote note: notesList)
                    journalList.add(note);
                Intent intent2 = new Intent(getActivity().getApplicationContext(),BarChart_Journal_Activity.class);
                intent2.putExtra("journalList", journalList);
                startActivity(intent2);
                break;
        }
        return false;
    }

以及我的条形图日记活动:

public class BarChart_Journal_Activity extends AppCompatActivity {

    ArrayList<JournalNote> journalList;
    LinearLayout layout;
    Map<String, Integer> source;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bar_chart_journal);

        Intent intent = getIntent();

        journalList = (ArrayList<JournalNote>) intent.getSerializableExtra("jounalList");

        source = getSource(journalList);

        layout = findViewById(R.id.layoutBar);
        layout.addView(new BarChartView(getApplicationContext(), source));
        }

        private Map<String, Integer> getSource( List<JournalNote> notes)
        {
            if(notes == null || notes.isEmpty())
                return new HashMap<>();
            else{
                Map<String,Integer> results = new HashMap<>();
                for(JournalNote journalNote: notes)
                    if(results.containsKey(journalNote.getNotetype()))
                        results.put(journalNote.getNotetype().toString(),  results.get(journalNote.getNotetype())+1);

                    else { results.put(journalNote.getNotetype().toString(),1);}

                return results;
            }

        }

}

我的journalnote类是可序列化的。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题