سؤال

أقوم بتطوير تطبيق ، في طلبي ، أستخدم ListView لعرض البيانات باستخدام DOM Parsing ، أريد تذييل في ListView ، عندما أنقر على Footer Footer المزيد من البيانات إضافة إلى عرض القائمة ، أرفق الصورة ، وأود هذا التصميم ، العملية ، يرجى الرجوع

FIG1-Tooter مثل "المزيد من الأخبار"
alt text

alt text

تم إضافة سجل إضافي 10 مضافة في ListView

هل كانت مفيدة؟

المحلول

قم بإنشاء تصميم عرض تذييل يتكون من نص تريد تعيينه كذين تذييل ثم حاول

View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);

يمكن أن يكون تخطيط تذييل شيء مثل هذا:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="7dip"
    android:paddingBottom="7dip"
    android:orientation="horizontal"
    android:gravity="center">

    <LinearLayout 
        android:id="@+id/footer_layout" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_gravity="center">

    <TextView 
        android:text="@string/footer_text_1" 
        android:id="@+id/footer_1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="14dip" 
        android:textStyle="bold" 
        android:layout_marginRight="5dip" />
    </LinearLayout>
</LinearLayout> 

يمكن أن يكون فئة النشاط:

public class MyListActivty extends ListActivity {
    private Context context = null;
    private ListView list = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        list = (ListView)findViewById(android.R.id.list);

        //code to set adapter to populate list
        View footerView =  ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
        list.addFooterView(footerView);
    }
}

نصائح أخرى

أعلم أن هذا سؤال قديم للغاية ، لكنني غوغل طريقي إلى هنا ووجدت أن الإجابة غير مرضية بنسبة 100 ٪ ، لأنه كما ذكر GCL1 - وبهذه الطريقة ، فإن تذييل التذييل ليس حقًا على الشاشة - إنه مجرد "إضافة" "إلى القائمة.

خلاصة القول - للآخرين الذين قد يكونون في طريقهم إلى هنا - وجدت الاقتراح التالي هنا: ثابت ودائمًا تذييلًا مرئيًا أدناه ListFragment

حاول القيام بذلك على النحو التالي ، حيث يتم التركيز على الزر (أو أي عنصر تذييل) مدرج أولاً في XML - ثم يتم إضافة القائمة على أنها "layout_above":

<RelativeLayout>

<Button android:id="@+id/footer" android:layout_alignParentBottom="true"/> 
<ListView android:id="@android:id/list" **android:layout_above**="@id/footer"> <!-- the list -->

</RelativeLayout>

الإجابات هنا عفا عليها الزمن قليلا. على الرغم من أن الكود يبقى كما هو الحال في بعض التغييرات في السلوك.

public class MyListActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        TextView footerView = (TextView) ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_view, null, false);
        getListView().addFooterView(footerView);
        setListAdapter(new ArrayAdapter<String>(this, getResources().getStringArray(R.array.news)));
    }
}

معلومات عن addFooterView() طريقة

أضف طريقة عرض ثابت لتظهر في أسفل القائمة. إذا addFooterView() يُطلق عليه أكثر من مرة ، ستظهر وجهات النظر بالترتيب الذي تمت إضافته. يمكن أن تأخذ المشاهدات التي تمت إضافتها باستخدام هذه المكالمة إذا أرادوا.

معظم الإجابات فوق الإجهاد نقطة مهمة للغاية -

addFooterView() يجب الاتصال قبل الاتصال setAdapter(). هذا هو So ListView يمكنه لف المؤشر الموردة بواحد من شأنه أن يفسر أيضًا طرق عرض الرأس والتذييل.

من Kitkat لقد تغير هذا.

ملاحظة: عند تقديمها لأول مرة ، لا يمكن استدعاء هذه الطريقة إلا قبل تعيين المحول باستخدام SetAdapter (ListAdapter). بدءًا من KitKat ، قد يتم استدعاء هذه الطريقة في أي وقت. إذا لم يمتد محول ListView الخاص بـ HeaderViewListAdapter ، فسيتم لفه بمثيل داعم لـ WrapperListAdapter.

توثيق

إذا كانت ListView طفلًا في القائمة:

getListView().addFooterView(
    getLayoutInflater().inflate(R.layout.footer_view, null)
);

(داخل oncreate ())

النشاط الذي تريد إضافة ListView Footer ، وقد قمت أيضًا بإنشاء حدث على ListView Footer Click.

  public class MainActivity extends Activity
{

        @Override
        protected void onCreate(Bundle savedInstanceState)
         {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            ListView  list_of_f = (ListView) findViewById(R.id.list_of_f);

            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View view = inflater.inflate(R.layout.web_view, null);  // i have open a webview on the listview footer

            RelativeLayout  layoutFooter = (RelativeLayout) view.findViewById(R.id.layoutFooter);

            list_of_f.addFooterView(view);

        }

}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg" >

    <ImageView
        android:id="@+id/dept_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/dept_nav" />

    <ListView
        android:id="@+id/list_of_f"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/dept_nav"
        android:layout_margin="5dp"
        android:layout_marginTop="10dp"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:listSelector="@android:color/transparent" >
    </ListView>

</RelativeLayout>

في هذا السؤال ، أفضل إجابة لا تعمل بالنسبة لي. بعد ذلك وجدت هذه الطريقة لعرض تذييل ListView ،

LayoutInflater inflater = getLayoutInflater();
ViewGroup footerView = (ViewGroup)inflater.inflate(R.layout.footer_layout,listView,false);
listView.addFooterView(footerView, null, false);

وإنشاء تخطيط جديد call footer_layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Done"
        android:textStyle="italic"
        android:background="#d6cf55"
        android:padding="10dp"/>
</LinearLayout>

إذا لم يكن العمل ارجع هذه المقالة يسمع

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top