lundi 15 octobre 2018

How to show checkbox at listview?

I'm making some apps , but need your help.

What I want :

1.checkbox to be visible when I click the button.

  1. Process events when you click on a list view (go to the corresponding information layout)

  2. When a checkbox is selected in a list view, the value is saved as a different activity.

    XML

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <!--tab으로 보여지는 위젯-->
            <TabWidget
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@android:id/tabs"
               >
    
            </TabWidget>
    
    
    
    
            <!--tab 누를 때 마다 바뀌어지는 화면-->
    
    
    
                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@android:id/tabcontent"
                    >
    
                    <!--1번 탭 -->
    
    
    
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:id="@+id/pectoralis"
                            android:scrollbars="vertical"
    
                            >
    
                            <ListView
                                android:id="@+id/pectoralisView"
                                android:layout_width="match_parent"
                                android:layout_height="0dp"
                                android:textAlignment="center"
                                android:layout_weight="1"
                                android:choiceMode="multipleChoice"
                                >
                            </ListView>
    
    
            <!-- <com.melnykov.fab.FloatingActionButton
                 android:id="@+id/fab"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="bottom|right"
                 android:layout_margin="16dp"
                 android:src="@drawable/baseline_add_circle_outline_black_18dp"
                 app:fab_colorDisabled="@color/fabPrimary"
                 app:fab_colorPressed="@color/fabPressed"
                 app:fab_colorRipple="@color/fabRipple"/> -->
    
                            <Button
                                android:id="@+id/addbtn1"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="#ff00ff"
                                android:textSize="20dp"
                                android:text="운동일지에 추가하기"/>
    
                            <Button
                                android:id="@+id/savebtn1"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="#ff00ff"
                                android:textSize="20dp"
                                android:text="저장하기"
                               />
    
    
    
                        </LinearLayout>
    
    

    package com.hcs.com.staystrong; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TabHost;

    public class FindExeActivity extends TabActivity {

    //private FloatingActionButton fab;

    static final String[] Pec_Menu = {"바벨 벤치프레스","덤벨 벤치프레스","크로스 오버","딥스","푸쉬 업","인클라인 벤치프레스",
            "디클라인 벤치프레스","덤벨플라이","펙덱 플라이",};
    
    static final String[] Sho_Menu = {"숄더 프레스", "덤벨 숄더 프레스", "비하인드 넥 프레스" , "스미스머신 프레스",
    "업라이트 로우","사이드 레터럴 레이즈","머신 레이털 레이즈","케이블 레터럴스","벤트-오버 레티럴 레이즈",};
    
    static final String[] Back_Menu = {"케이블 풀 다운","비하인드 넥 풀 다운","케이블 로우","T바 로우","원암 덤벨 로우",
    "풀 업","데드 리프트","덤벨 풀 오버"};
    
    static final String[] Low_Menu = {"스쿼트","스미스머신 백 스쿼트","레그 프레스","레그 익스텐션","라잉 레그 컬"};
    
    static final String[] Biceps_Menu = {"바벨 컬","덤벨 컬","컨센트레이션 컬","해머 컬","바벨 리버스 컬", "인클라인 얼티네이트 덤벨 컬"};
    
    static final String[] Triceps_Menu = {"클로즈-그립 바벨 프레스","클로즈-그립 스미스 머신 프레스","덤벨 킥 백",
            "스탠딩 트라이셉스 익스텐션","얼티네이트 덤벨 익스텐션"};
    
    
    
    
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find);
    
        /*
        ListView listview;
        ListViewAdapter adapter;
    
        adapter = new ListViewAdapter();
    
    
        ListView listview1 = (ListView)findViewById(R.id.pectoralisView);
        listview1.setAdapter(adapter);
    
        listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
                ListViewItem item = (ListViewItem) parent.getItemAtPosition(position);
    
                String titleStr = item.getTitle();
    
            }
        });
        */
    
    
    
    
        Button addbtn1 = (Button)findViewById(R.id.addbtn1);
         final Button savebtn1 = (Button)findViewById(R.id.savebtn1);
    
        Button addbtn4 = (Button)findViewById(R.id.addbtn4);
        final Button savebtn4 = (Button)findViewById(R.id.savebtn4);
    
    
    
    
    
    
                ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_multiple_choice,Pec_Menu);
    
                final ListView p_listview = (ListView)findViewById(R.id.pectoralisView);
                p_listview.setAdapter(adapter);
    
                p_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        String strText = (String)parent.getItemAtPosition(position);
    
                switch (position)
                {
                    case 0:
                        Intent bbp = new Intent(FindExeActivity.this, BBPActivity.class);
                        startActivity(bbp);
    
                    case 1:
    
    
    
                }
    
            }
        });
    
        p_listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        p_listview.setChoiceMode(View.INVISIBLE);
    
    
    
    
    
        addbtn1.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                p_listview.setChoiceMode(View.VISIBLE);
                Log.e("ss","addbtnclick");
    
            }
        }) ;
    
    



Aucun commentaire:

Enregistrer un commentaire