Join FlipAndroid.COM Telegram Group: https://t.me/joinchat/F_aqThGkhwcLzmI49vKAiw


Agregar elemento al final listview android

Hola experto aquí es un ejemplo que presentan listview dinámico obtener los valores de list1.now me gustaría añadir el artículo en la posición final (al fin). No significa sobrescribir el elemento cuando insert.it será paginación del elemento. Así que por favor alguien me ayude?

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; } } } 

2 Solutions collect form web for “Agregar elemento al final listview android”

Puede agregar una "vista de pie de página" que siempre aparecerá en la parte inferior de su lista:

 View footerView = getLayoutInflater().inflate(R.layout.footer_layout, lister1, false); lister1.addFooterView(footerView); 

Cuando agrega un nuevo elemento en su dataSource, actualizará el adaptador por

 itemsAdapter.notifyDataSetChanged(); 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.