Here is an example that presents dynamic listview get values from list1. Now I would like to add item at end position(at last).means not overwrite item when we insert. It will be paging of item. Please anybody help me?
package com.list.viewer;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
/** http://www.android-codes-examples.blogspot.com/ */
public class ListViewExample extends Activity {
private String[] list1 = { "Icon", "Icon Creator", "Image", "Image Creator" };
private ListView lister1;
Button btn_add;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lister1 = (ListView) findViewById(R.id.ListView1);
btn_add =(Button)findViewById(R.id.btn_add);
String[] list2 = { "nikunj", "patel", "hi", "this" };
ItemsAdapter itemsAdapter = new ItemsAdapter(ListViewExample.this,
R.layout.list, list2);
lister1.setAdapter(itemsAdapter);
btn_add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
String[] list2 = { "nikunj", "patel", "hi", "this" };
ItemsAdapter itemsAdapter = new ItemsAdapter(ListViewExample.this,
R.layout.list, list2);
lister1.setAdapter(itemsAdapter);
}
});
/*lister1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int positon, long arg3) {
String[] lister = null;
switch (positon) {
case 0:
lister = list21;
break;
case 1:
lister = list22;
break;
case 2:
lister = list23;
break;
case 3:
lister = list24;
break;
default:
lister = list21;
}
lister2.setAdapter(new ArrayAdapter<String>(
ListViewExample.this,
android.R.layout.simple_list_item_1, lister));
}
});*/
}
private class ItemsAdapter extends BaseAdapter {
String[] items;
public ItemsAdapter(Context context, int textViewResourceId,
String[] items) {
this.items = items;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
System.out.println("position is "+position);
TextView mDescription;
View view = convertView;
//ImageView image;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list, null);
}
if(position == 3)
{
mDescription = (TextView) view.findViewById(R.id.desc);
mDescription.setText(items[position]);
}else
{
mDescription = (TextView) view.findViewById(R.id.desc);
mDescription.setText(items[position]);
}
//image = (ImageView) view.findViewById(R.id.image);
//image.setBackgroundResource(R.id.image);
return view;
}
public int getCount() {
return items.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
}
}
You can add a "footer view" which will always show at the bottom of your list:
View footerView = getLayoutInflater().inflate(R.layout.footer_layout, lister1, false);
lister1.addFooterView(footerView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With