Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView-从两个不同的对象列表中获取的项的内容_Android_List_Listview_Android Listview_Android Arrayadapter - Fatal编程技术网

Android ListView-从两个不同的对象列表中获取的项的内容

Android ListView-从两个不同的对象列表中获取的项的内容,android,list,listview,android-listview,android-arrayadapter,Android,List,Listview,Android Listview,Android Arrayadapter,我想将存储在两个列表中的项目信息放入listview。问题是,当我开始滚动时,我没有检查的BTN会突出显示,我认为它与recycler连接,当必须创建新视图时会调用recycler 我的代码是这样的: 自定义项目视图的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_w

我想将存储在两个列表中的项目信息放入listview。问题是,当我开始滚动时,我没有检查的BTN会突出显示,我认为它与recycler连接,当必须创建新视图时会调用recycler

我的代码是这样的:

自定义项目视图的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/kalendarz_frag_lay_child_row_separator"
android:orientation="horizontal" >

<LinearLayout
   android:id="@+id/how_look_child_presecence_item_child_btn"
   android:layout_width="200dp"
   android:layout_height="match_parent"
   android:background="@color/White"
   android:clickable="true"
   android:orientation="horizontal" >

    <ImageView 
    android:layout_margin="10dp"
    android:id="@+id/how_look_child_presecence_item_picture_of_child"
    android:layout_height="80dp"
    android:layout_width="80dp"
    android:scaleType="centerInside"
    android:src="@drawable/child_avatar"
    android:adjustViewBounds="true"
    ></ImageView> 

<com.example.kinder.TextViewWithFont
    android:id="@+id/how_look_child_presecence_item_name_surname_of_child"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:fontFamily="Lato-Reg.ttf"
    android:gravity="center_vertical" />
</LinearLayout>



 <LinearLayout 
   android:layout_width="match_parent"
   android:layout_height="100dp"
   android:orientation="horizontal"
   android:weightSum="11" >


<ImageButton 
    android:id="@+id/how_look_child_presecence_item_obecny_but"
    android:src="@drawable/btn_obecny"
    android:layout_height="100dp"
    android:layout_width="0dp"
    android:layout_weight="2"
    android:background="@color/group_layout_item_back_match"

    />

<ImageButton
    android:id="@+id/how_look_child_presecence_item_nieobecny_but"
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:layout_weight="2"
    android:background="@color/White"
    android:src="@drawable/btn_nieobecny" />

 <TextView android:id="@+id/how_look_child_presecence_item_absence_caused" 
    android:layout_width="0dp"
    android:layout_weight="3"
    android:layout_height="100dp"
    android:background="@color/group_layout_item_back_match"

    >

</TextView>
 </LinearLayout>


 </LinearLayout>

正如我所说的,当我开始滚动时,问题就开始了,滚动上的ArrayAdapter从一个列表中获取信息。有没有办法从两个列表中获取信息,以避免在滚动显示数据时出现问题?

“我认为它与回收商有关”domyslam sie,ze chodzi o przyciski presentImageButton I unpresentImageButton。。。德。。。如果(takenOneActivityDataClass.presenceActivityDataValue.getIdOfState()!=0)。。。moim zdaniem i tak za dużo siędzieje w getView…您是否尝试将按钮设置为在listview中显示的android:focusable=“false”android:focusableInTouchMode=“false”?@Selvin是的,这是答案。我确信,如果我在自定义项视图的布局中设置此默认值,它将在listview中以相同的方式显示,并且我不需要在myCustomAdapter中执行任何操作。奇怪的行为伊莫诺,这并不奇怪。。。如果转换视图!=如果为null,则会得到旧视图(因为它比创建新视图更有效)。。。用突出显示的按钮。。。了解ListView的好资源:对于这个链接,我将观看它。从你的评论中做出回答,我会接受这一点
private class MyChildInitialAdapter extends ArrayAdapter<ChildShortInfoClass> {


        public MyChildInitialAdapter() {
            // here we add some info which is needed to create ArrayAdapter here our custom
            //first the activity where it is 
            // second is exposition of product so how it will be look every single row 
            // it was created in product_exposition.lay
            // the third one is our List where we stored all items/object (containerOfProducts)
            super(getActivity(), R.layout.how_look_child_presecence_item, App_class.listOfChild );
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // to make smth with view we need to take it 
            View takenView = convertView;


            if(takenView == null)
            {                   
                takenView = getActivity().getLayoutInflater().inflate(R.layout.how_look_child_presecence_item, null, false);
            }
            // find the current object 
            final ChildShortInfoClass currentChild = App_class.listOfChild.get(position);               

            // layout of bio
            LinearLayout goToBioChildBtnLayout = (LinearLayout)takenView.findViewById(R.id.how_look_child_presecence_item_child_btn);
            // here we add click event to go to bio of child  
            goToBioChildBtnLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Toast.makeText(getActivity(), "child with id " +Integer.toString(currentChild.getId()), Toast.LENGTH_LONG).show();
                    ((MainScreen)getActivity()).showBioOfChoosenBaby(currentChild.getId()); 
                }
            });

            // here we would need to add text about child so name and surname 
            TextView childName = (TextView)takenView.findViewById(R.id.how_look_child_presecence_item_name_surname_of_child);

            childName.setText(currentChild.getNameString()+ " " + currentChild.getSurnameString());             

            // button present
            final ImageButton presentImageButton = (ImageButton)takenView.findViewById(R.id.how_look_child_presecence_item_obecny_but);

            // button unpresent
            final ImageButton unpresentImageButton = (ImageButton)takenView.findViewById(R.id.how_look_child_presecence_item_nieobecny_but);

            // if data is download we set values in our lay for btns
            // like some child is came to kindergarden or smth like 
            // that 
            if(App_class.ifDataAboutChildActivityIsDownloaded)
            {
                 ChildActivityDataClass currentChildActivityDataClass = null;
                for (ChildActivityDataClass item : App_class.listOfAcitvityDataOfChild) 
                {
                    if(item.getIdOfChild()==currentChild.getId())
                    {
                        currentChildActivityDataClass = item;
                    }

                }
                final ChildActivityDataClass takenOneActivityDataClass = currentChildActivityDataClass;




                // if is diferent then 0 it means that this activity is checked in db, 
                // so it means that we don't need to setonclicklistener we just indicate 
                // if the child is presence or not 

                if(takenOneActivityDataClass.presenceActivityDataValue.getIdOfState()!=0)
                {
                    if(takenOneActivityDataClass.presenceActivityDataValue.getIdOfState() == App_class.presenceObecny)
                    {
                        presentImageButton.setImageResource(R.drawable.btn_obecny_active);
                        presentImageButton.setEnabled(false);
                        unpresentImageButton.setImageResource(R.drawable.btn_nieobecny);
                        unpresentImageButton.setEnabled(false);
                    }
                    else if (takenOneActivityDataClass.presenceActivityDataValue.getIdOfState() == App_class.presenceNieobecny) 
                    {
                        unpresentImageButton.setImageResource(R.drawable.btn_nieobecny_active);
                        unpresentImageButton.setEnabled(false);
                        presentImageButton.setImageResource(R.drawable.btn_obecny);
                        presentImageButton.setEnabled(false);
                    } 
                }       

                    // unpresnet button onClickListener
                    presentImageButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) 
                        {                               
                                presentImageButton.setImageResource(R.drawable.btn_obecny_active);
                                presentImageButton.setEnabled(false);
                                unpresentImageButton.setImageResource(R.drawable.btn_nieobecny);
                                unpresentImageButton.setEnabled(false);
                                Log.i("clicked of id", "current child "+ Integer.toString(currentChild.getId())+
                                                        "currentChildActivityDataClass " + Integer.toString(takenOneActivityDataClass.getIdOfChild()));



                                ChangeTheActivityStatesInInternalList.changePresenceIdOfStateForParticularChild(currentChild.getId(), 15);

                        }
                    });                 

                    // unpresnet button onClickListener
                    unpresentImageButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) 
                        {                               
                                unpresentImageButton.setImageResource(R.drawable.btn_nieobecny_active);
                                unpresentImageButton.setEnabled(false);
                                presentImageButton.setImageResource(R.drawable.btn_obecny);
                                presentImageButton.setEnabled(false);
                                Log.i("clicked of id", "current child "+ Integer.toString(currentChild.getId())+
                                        "currentChildActivityDataClass " + Integer.toString(takenOneActivityDataClass.getIdOfChild()));
                                ChangeTheActivityStatesInInternalList.changePresenceIdOfStateForParticularChild(currentChild.getId(), 16);

                        }
                    });                 
                }                   
            //}             
            return takenView;
        }
     }
 App_class.listOfChild  - contain id of every child/ name / surname 
 App_class.listOfAcitvityDataOfChild - contain id of every child/ info if the first btn should be marked / info if the second btn should be marked