列表视图后,Android页脚 [英] Android footer after listview
问题描述
我现在面临应用程序崩溃的问题时,我想显示列表视图下方的页脚按钮。我重视我的XML code和活动code兹。任何帮助将是非常美联社preciated。
ContactListActivity.java
公共类ContactListActivity1扩展ListActivity {
静态的ArrayList<串GT; IDS =新的ArrayList<串GT;(); LV的ListView; @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
ContactList1 contactList = this.getContacts();
ArrayAdapter< Contact1>适配器=新ContactAdapter1(这一点,
contactList.getContacts());
// LoadMore按钮
按钮btnLoadMore =新按钮(本);
btnLoadMore.setText(加载更多); 视图V = getLayoutInflater()膨胀(R.layout.contactlistitem,NULL); lv.addFooterView(btnLoadMore);
lv.setAdapter(适配器); }
和我的XML code
<?XML版本=1.0编码=UTF-8&GT?;<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_alignParentRight =真
> <的TextView
机器人:ID =@ + ID / txtDisplayName
机器人:layout_width =250dp
机器人:layout_height =WRAP_CONTENT
机器人:文字=TextView的
>< / TextView的>
< ImageView的机器人:ID =@ + ID / contact_image
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
/> < ListView控件
机器人:ID =@ + ID / contactList1
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_above =@ + ID / txtDisplayName
/>< / LinearLayout中>
是的,你犯了一个错误 -
-
您正在扩展
ListActivity
那么,是LV = getListView()
在$ C $角 -
或者,你应该给
列表=(ListView控件)findViewById(android.R.id.list);
后您的超。的onCreate(savedInstanceState);
在的onCreate
由于,延长 ListActivity
这些都是很重要的。这似乎不是合适的与你的code。你最好有看看这个例子如何?启动应用程序前加入列表视图页脚。
I am facing a problem of application crash when I wanted to display a footer button underneath the list view. I have attached my xml code and activity code herewith. Any help will be highly appreciated.
ContactListActivity.java
public class ContactListActivity1 extends ListActivity {
static ArrayList<String> ids = new ArrayList<String>();
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContactList1 contactList = this.getContacts();
ArrayAdapter<Contact1> adapter = new ContactAdapter1(this,
contactList.getContacts());
// LoadMore button
Button btnLoadMore = new Button(this);
btnLoadMore.setText("Load More");
View v = getLayoutInflater().inflate(R.layout.contactlistitem,null);
lv.addFooterView(btnLoadMore);
lv.setAdapter(adapter);
}
And my XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
>
<TextView
android:id="@+id/txtDisplayName"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="TextView"
>
</TextView>
<ImageView
android:id="@+id/contact_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:id="@+id/contactList1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/txtDisplayName"
/>
</LinearLayout>
Yes, You made a mistake -
You're extending
ListActivity
so where islv = getListView()
in your code.Or, you should give
list = (ListView)findViewById(android.R.id.list);
after yoursuper.onCreate(savedInstanceState);
in youronCreate
Because, extending ListActivity
these are important. It seems not proper with your code. You better have look at this example How to add Footer in list view? before starting your application.
这篇关于列表视图后,Android页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!