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

custom listview에서 체크박스 이용하기 질문입니다.

0 추천

안녕하세요. 안드로이드스튜디오를 공부하고 있는 학생입니다.

custom listview를 이용해 리스트뷰를 표현해주고 있습니다.

--------------------------------

안녕 안녕 ㅁ

반갑 반갑 ㅁ

즐검 즐검 ㅁ

모름 모름 ㅁ

--------------------------------

전체체크 / 체크항목삭제

 

이런식으로 표현해주고 싶습니다.

저의 현재 문제는 전체체크 부분과, 체크항목삭제 부분을 구현을 못하겠습니다.

아래는 현재까지 작성한 코드를 첨부하겠습니다

어떤방식으로 하면될지 알려주시면 감사하겠습니다!

 

public class Line_past_main extends AppCompatActivity {

    private Context mContext;
    private Activity mActivity;

    private ConstraintLayout mRelativeLayout;
    private Button mButton;
    private ImageView mImageView, mImageView2, mImageView3, mImageView4;
    private ProgressDialog pDialog;
    private ListView lv2;
    private EditText editTextPw;

    private List<CellContent_line> contentList = new ArrayList<>(); // List to store collection of contents to be displayed
    ArrayAdapter<CellContent_line> adapter;
   
    ArrayList<HashMap<String, String>> contactList;

    ListView listView;

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

        setCustomActionbar(); //커스텀액션바

        contactList = new ArrayList<>();
        lv2 = (ListView) findViewById(R.id.vvv);


        // Get the application context
        mContext = getApplicationContext();

        // Get the activity
        mActivity = Line_past_main.this;

        getCellContent(); // Get Json content from file and store in collection.
        fillContentOnView(); // populate listview.
       //  contentClickListener(); // listview click Listener.
    }


    public void getCellContent() {
        contentList.clear();
        try {
            JSONObject jsonFile = new GetJson().execute("json파일주소.php").get();
            //     toast = Toast.makeText(getApplicationContext(), loadToastText, Toast.LENGTH_SHORT);
           //       toast.show();
            JSONArray jsonCellContents = jsonFile.getJSONArray("result");
            System.out.println(jsonCellContents.toString());
            for (int i = 0; i < jsonCellContents.length(); i++)

            {
                // Parsing all items of Json array.
                JSONObject subJson = (JSONObject) jsonCellContents.get(i);

                String line_start, line_stop, line_type;

                line_start = subJson.getString("Start");
                line_stop = subJson.getString("Stop");
                line_type = subJson.getString("Type");

                //    String check1 = subJson.getString("Team");
               //  String check2 = subJson.getString("Class");
               //String check3 = subJson.getString("Part");


                contentList.add(new CellContent_line(line_start, line_stop, line_type));

            }

        } catch (Exception e) {
            // toast = Toast.makeText(getApplicationContext(), errorToastText, Toast.LENGTH_SHORT);
           //   toast.show();
        }

    }

    private void fillContentOnView() {
        adapter = new contentListViewAdapter();
        listView = (ListView) findViewById(R.id.vvv);
        listView.setAdapter(adapter);
    }


    private class contentListViewAdapter extends ArrayAdapter<CellContent_line> {
        public contentListViewAdapter() {
            super(Line_past_main.this, R.layout.line_list_item, contentList);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            final float scale = getResources().getDisplayMetrics().density;
            int iconDimension = (int) (100 * scale);
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.line_list_item, null);
                holder = new ViewHolder();
                //   holder.icon = (ImageView) convertView.findViewById(R.id.iconView);
                holder.line_start = (TextView) convertView.findViewById(R.id.start);
                holder.line_stop = (TextView) convertView.findViewById(R.id.finish);
                holder.line_type = (TextView) convertView.findViewById(R.id.checkname);


                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            CellContent_line currentContent = contentList.get(position);
            holder.line_start.setText(currentContent.getLine_start());
            holder.line_stop.setText(currentContent.getLine_stop());
            holder.line_type.setText(currentContent.getLine_type());
           
            return convertView;
        }
    }
   
    static class ViewHolder {
        TextView line_start;
        TextView line_stop;
        TextView line_type;
    }

    private class GetJson extends AsyncTask<String, Integer, JSONObject> {
        @Override
        protected JSONObject doInBackground(String... params) {
            JSONObject json = null;
            try {
                json = readUrl(params[0]);
            } catch (Exception e) {
                //   toast = Toast.makeText(getApplicationContext(), errorToastText, Toast.LENGTH_SHORT);
               //  toast.show();
            } finally {
                return json;
            }
        }

        private JSONObject readUrl(String url) throws Exception {
            InputStream inputStream = new URL(url).openStream();
            JSONObject json = null;
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
                String jsonText = readAll(reader);
                json = new JSONObject(jsonText);
                return json;
            } catch (Exception e) {
                //    toast = Toast.makeText(getApplicationContext(), errorToastText, Toast.LENGTH_SHORT);
               //      toast.show();
            } finally {
                inputStream.close();
                return json;
            }
        }

        private String readAll(Reader rd) throws IOException {
            StringBuilder sb = new StringBuilder();
            int cp;
            while ((cp = rd.read()) != -1) {
                sb.append((char) cp);
            }
            return sb.toString();
        }
    }

 

익명사용자 님이 2017년 6월 2일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...