마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

배열의 값을 받아와서 0일 경우에 특정 텍스트가 나오게 하고 싶습니다.

0 추천
import java.util.ArrayList;

public class TimetableActivity extends AppCompatActivity {
    RecyclerView recyclerView3;
    MyRecyclerAdapter3 adapter;
    ArrayList<S3List> arr = new ArrayList<S3List>();
    String strS3id;

    int s2id;

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

        Intent intent = getIntent();

        final String strS2id = intent.getExtras().getString("strS2id");
        s2id = Integer.parseInt(strS2id);

        String strS1name = intent.getExtras().getString("strS1name");
        String strS2date = intent.getExtras().getString("strS2date");

        ActionBar ab = getSupportActionBar();
        ab.setTitle(strS1name + " > " + strS2date);



        TextView textViewName = (TextView)findViewById(R.id.empty_view);
            textViewName.setText("방문일정을 추가해주세요.");

        recyclerView3 = (RecyclerView)findViewById(R.id.recyclerView3);
        recyclerView3.setLayoutManager(new LinearLayoutManager(this));
        recyclerView3.setItemAnimator(new DefaultItemAnimator());

        adapter = new MyRecyclerAdapter3(arr, R.layout.list_s3);
        rcViewUpdate(s2id);

        recyclerView3.addOnItemTouchListener(new RecyclerViewOnItemClickListener(getApplicationContext(), recyclerView3, new RecyclerViewOnItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                String strpid = arr.get(position).getPid();

                Intent intent = new Intent(TimetableActivity.this, PlaceInformationActivity.class);
                intent.putExtra("strpid", strpid);
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int position) {
                strS3id = arr.get(position).getS3id();


    private void rcViewUpdate(int id) {
        DBAccess access = new DBAccess(this);

        access.openDataBase();
        arr.clear();

        Cursor c = access.dbS3Select(id);

        while (c.moveToNext()) {
            String s3id = c.getString(0);
            String s2id = c.getString(1);
            String pid = c.getString(2);
            String stime = c.getString(3);
            String etime = c.getString(4);
            String pname = c.getString(5);

            S3List s3List = new S3List();
            s3List.setS3id(s3id);
            s3List.setS2id(s2id);
            s3List.setPid(pid);
            s3List.setsTime(stime);
            s3List.seteTiem(etime);
            s3List.setPname(pname);

            arr.add(s3List);
        }
        recyclerView3.setAdapter(adapter);
    }

    @Override
    public void onResume() {
        super.onResume();

        rcViewUpdate(s2id);
    }
}

 

배열을 받아와서 배열에 아무것도 저장이 되어있지 않을경우

방문 일정을 추가해주세요 라는 메세지를 띄워주고싶은데

 

이 부분을

 

TextView textViewName = (TextView)findViewById(R.id.empty_view);
    textViewName.setText("방문일정을 추가해주세요.");

if(arr.size() == 0) or if(arr.isEmpty == true) 로 해도

전혀 인식을 못하고 메세지가 계속 나옵니다.

이런 경우에는 어떻게 조건을 넣어야할지 모르겠습니다 ㅠ

 

 

 

이런식으로 아예 텍스트가 고정이 되어있습니다.

celt (120 포인트) 님이 2017년 10월 22일 질문
db 에서 불러와서 사용하고있네요.

db부터 체크해보심이 좋을듯합니다.

1개의 답변

0 추천
arr.size() 를 찍어보세요. 그리고 0이 아니라면, arr에 저장되어있는 값이 뭔지 확인해보시구요.
길버트공원 (1,720 포인트) 님이 2017년 10월 22일 답변
...