android listview : footer view auto fill parent - android

i have a listview. i set position 20(last position), after i want add footer start
item last listview to bottom.
description:
http://i.imgur.com/I5DFV.jpg
i have set height footer view. but i don't.
<?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="10000dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="FOOTER"
android:background="#cf9f99" />
</LinearLayout>
listview :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".demoAddListViewFooterActivity">
<ListView
android:id="#+id/list_items"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Activity :
LayoutInflater inflater = getLayoutInflater();
ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer, listItem,
false);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, numbers);
listItem.addFooterView(footer,
null,
false);
listItem.setAdapter(adapter);
listItem.setSelection(20);
can you help me.

Related

Listview inside Listview only one Element

Hi i'm trying to put a listview inside a listview inside a listview.
The only problem is only the first listview is showing all elements correctly.
Every listview after that only contains one element.
UPDATE:
Creating my own non-scrollable listview fixed the problem.
https://stackoverflow.com/a/24629341/3713144
Here is some code:
activity_anlagen_details.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"></include>
<TextView
android:id="#+id/anlagenName_textview"
android:layout_width="0dp"
android:layout_height="60dp"
android:gravity="center|center_vertical"
android:padding="3dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#424242" />
<ListView
android:id="#+id/listChecklisten"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
anlagen_checklisten_listview.xml:
<?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="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/checkliste_name"
android:layout_gravity="center_horizontal"
android:gravity="center|center_vertical"/>
<ListView
android:id="#+id/listChecklistenPunkte"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and so on...
What i'm trying to do now is setting an ArrayAdapter for all listviews:
AnlagenDetailsActivity:
...
long anlagenId = getIntent().getLongExtra("anlagen_id", 0);
Log.d(logger, "Details for Anlage: " + anlagenId);
LocalAnlagenAccessor accessor = new LocalAnlagenAccessor(this);
Anlage anlage = accessor.readAnlage(anlagenId);
TextView anlagenName = (TextView) findViewById(R.id.anlagenName_textview);
anlagenName.setText(anlage.getName());
ListView listView = (ListView) findViewById(R.id.listChecklisten);
AnlagenChecklistenAdapter adapter = new AnlagenChecklistenAdapter(this);
listView.setAdapter(adapter);
adapter.addAll(anlage.getChecklisten());
...
AnlagenChecklistenAdapter:
...
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View checklisteView = inflater.inflate(R.layout.anlagen_checklisten_listview, parent, false);
TextView checklisteName = (TextView) checklisteView.findViewById(R.id.checkliste_name);
checklisteName.setText(getItem(position).getArt());
ListView listView = (ListView) checklisteView.findViewById(R.id.listChecklistenPunkte);
AnlagenChecklistenPunktAdapter adapter = new AnlagenChecklistenPunktAdapter(checklisteView.getContext());
listView.setAdapter(adapter);
adapter.addAll(getItem(position).getChecklistenPunkte());
return checklisteView;
}
...
The same goes on for one more listview.
What am I doing wrong here?

Android Sliding Menu Basic

having a trouble here with the sliding tabs. So I have completed the tutorial but when i had a ListView to my Pager it only shows on the bottom of the screen.
Here is my XML:
<?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="match_parent"
android:orientation="vertical">
<com.example.ambidata.innovway.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
</LinearLayout>
And my XML from ListView:
<?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:orientation="vertical" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/issue_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_row_selector"/>
</LinearLayout>
Fragment Code:
public class TabIssues extends Fragment {
private ListView mainListView ;
private CustomListAdapter_Issues listAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle b = getArguments();
int user_id = b.getInt("user_id");
boolean all = b.getBoolean("all");
WSConnectionIssues runner = new WSConnectionIssues(user_id, all);
runner.execute();
while (runner.download == AsyncTask.Status.RUNNING)
{
try
{
Thread.sleep(1);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
View view = inflater.inflate(R.layout.activity_issues, container, false);
// Find the ListView resource.
mainListView = (ListView) view.findViewById(R.id.issue_list);
registerForContextMenu(mainListView);
// Create ArrayAdapter using the planet list.
View convertView = inflater.inflate(R.layout.row_issues, null);
listAdapter = new CustomListAdapter_Issues(this, runner.listIssues, convertView);
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter(listAdapter);
return view;
}
Im using the phone for debug...as you can see blank...then the first item of my listview and if you scroll the others are there!
Could you try the listview layout as:
<?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:orientation="vertical" >
<ListView
android:id="#+id/issue_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_row_selector"/>
</RelativeLayout>

How to scroll LinearLayout united with ListView in android

I am developing an android App.
I places LinearLayout on ListView. I would like to scroll LinearLayout united with ListView.
My xml is below.
Could you tell me how to implement above?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:choiceMode="singleChoice"
android:orientation="vertical" >
・・・
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice" />
</LinearLayout>
You should not put a ListView inside a ScrollView due to it being extremely expensive and defeats the purpose a ListView. Use a LinearLayout/RelativeLayout instead.
If you would like to populate the ListView items with a LinearLayout you will need to create an adapter that will get the data and populate the listView.
Here is some code that takes String values and displays them in the list.
public class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MySimpleArrayAdapter(Context context, String[] values) {
super(context, R.layout.rowlayout, values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(values[position]);
// change the icon for Windows and iPhone
String s = values[position];
if (s.startsWith("iPhone")) {
imageView.setImageResource(R.drawable.no);
} else {
imageView.setImageResource(R.drawable.ok);
}
return rowView;
}
}
Where you inflate the rowlayout in the getView - This will be your LinearLayout.
http://www.vogella.com/tutorials/AndroidListView/article.html#androidlists_adapterintro - For more information.
Use ScrollView (example) :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:choiceMode="singleChoice"
android:orientation="vertical" >
・・・
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
Remember that ScrollView can only have one child attribute, so you can f.e. use a Relative Layout to encapsulate LinearLayout and ListView
ListView has its own ScrollView, If you want to scroll LinearLayout then follow the this code.
Declare Scroll-view as parent and declare only one child Linearlayout inside it (Scrollview contain only one child)
Declare what ever you want inside the Linearlayout.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="3dp"
android:choiceMode="singleChoice"
android:orientation="vertical" >
.
.
.
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice" />
</LinearLayout>
</ScrollView>

listView Centered in a dialog in Android

I am trying to have the content of the ListView centered when displayed in a dialog.
This is my code to show the ListView
String[] myItems = {"item1", "item2", "item3"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, R.layout.setting_layout, myItems);
ListView list = (ListView) deleteDialog.findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setFadingEdgeLength(5);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paret, View viewClicked, int position, long id) {
// TODO Auto-generated method stub
}
}
And this is the xml part:
TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_gravity="center"
android:textSize="25sp"
and this is the layout of delete dialog:
<?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:layout_gravity="center_vertical|center_horizontal" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
Its running but the content is always displayed to left.
I tried this: How to set the text at center in ListView android application?
but it didn't work.
Hope anyone can guide me through.
this will work for u
<?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="wrap_content" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
You can try with
android:layout_gravity="center_vertical|center_horizontal"
I hope it helps
Change your LinearLayout to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">

How to add button in footer below listview in layout with fragment

How to add button in footer below listview in layout with fragment.
I have code as below:
In fragment java.
ListView listview;
Button button;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.category, container, false);
View footerView = inflater.inflate(R.layout.footer_category, null);
listview = (ListView) view.findViewById(R.id.categoryNewsItemGrid);
listview.addFooterView(footerView);
loadmore = (Button) footerView.findViewById(R.id.loadMore);
loadmore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("Mylog","Button can click");
}
});
return view;
}
/res/layout/category.xml
<?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:orientation="vertical" >
<ListView
android:id="#+id/categoryNewsItemGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#C5C5C5"
android:dividerHeight="2px" />
</LinearLayout>
/res/layout/footer_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footerCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/loadMore"
android:layout_width="fill_parent"
android:text="Load More" />
</LinearLayout>
And i get error(Force Close), if i see in logcat, i get message error Android Runtime in line 74, line 74 is:
View footerView = inflater.inflate(R.layout.footer_category, null);
My question, i want to add button in footer, below listview. like as this screenshot.
thanks.
You missed layout_height in your /res/layout/footer_category.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footerCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/loadMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More" />
</LinearLayout>

Categories

Resources